question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Must call joinMonster in a resolver on a field where the type is decorated with \"sqlTable\"

See original GitHub issue

Description

I used join-monster to convert graphql query into SQL query to fetch date from postgres. I have implemented a small example with the help of join-monster docs to achieve it. But when i try to run the graphql query i get error ‘“Must call joinMonster in a resolver on a field where the type is decorated with “sqlTable”.”’

Reproduction

schema.js

const graphql = require(‘graphql’); var _ = require(‘lodash’); const { Client } = require(‘pg’); const joinMonster = require(‘join-monster’).default; const knex = require(‘knex’);

const client = new Client({ user: ‘postgres’, host: ‘us-east-1.rds.amazonaws.com’, database: ‘graphqldb’, password: ‘’, port: 5432 });

client.connect();

var q = “SELECT * FROM cgh_graphql_user_details”;

client.query(q, function(err, results){ if(err) throw err; console.log(“results are”,results); client.end(); });

const { GraphQLObjectType, GraphQLID, GraphQLString, GraphQLInt, GraphQLList, GraphQLSchema

} = graphql

const User = new GraphQLObjectType({ name: ‘User’, sqlTable: ‘cgh_graphql_user_details’, uniqueKey: ‘id’, fields: () => ({ id: { type: GraphQLInt, sqlColumn: ‘id’ }, name: { description: ‘A user's first and last name’, type: GraphQLString, sqlColumn: ‘name’ }, age: { description: ‘A user's age’, type: GraphQLInt, sqlColumn: ‘age’ } }) })

const QueryRoot = new GraphQLObjectType({ name: ‘Query’,

fields: () => ({ user: { type: User, args: {id:{type: GraphQLInt}}, // how to write the WHERE condition where: (usersTable, args, context) => { if (args.id) return ${usersTable}.id = ${args.id} }, resolve: (parent, args, context, resolveInfo) => { // resolve the user and the comments and any other descendants in a single request and return the data! // all you need to pass is the resolveInfo and a callback for querying the database return joinMonster(resolveInfo, {}, sql => { // knex is a query library for SQL databases return knex.raw(sql) }) } } }) })

module.exports = new GraphQLSchema({ query: QueryRoot })

Environment

Development

Please provide the following:

  • Version of this library used: - v3.0.1

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
lorensrcommented, Oct 5, 2021

@koesper do you have sqlTable nested under extensions: { joinMonster: ... }}?

https://join-monster.readthedocs.io/en/stable/CHANGELOG/

1reaction
nancyobriencommented, Jun 3, 2021

sqlTable and uniqueKey apparently need to go into an extensions > joinMonster attribute: https://join-monster.readthedocs.io/en/latest/map-to-table/#table-name-details

Nice software, not nice examples. This change worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How It Works - Join Monster - Read the Docs
Once you map a GraphQLObjectType to a SQL table, any field with that type, along with all of its descendants, can be fetched...
Read more >
Graphql query into SQL query using join-monster
But when i try to run the graphql query I get error '"Must call joinMonster in a resolver on a field where the...
Read more >
join-monster-graphql-tools-adapter - npm
Fetch data for your graph-tools schema using join-monster. ... call joinMonster in the "user" resolver, and all child fields that are tagged ...
Read more >
Using Node.js Express to Quickly Build a GraphQL Server
To do so, you need to create what we call resolvers. ... So, inside the hello field, I had to define what type...
Read more >
A GraphQL-to-SQL Query Execution Layer for Batch Data ...
No need to manually write queries or update them when the schema changes. ... any type (and all its descendants) by calling joinMonster...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found