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.

Cannot read property 'sqlTable' of undefined

See original GitHub issue

Join-monster fails with

(node:3555) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 11): TypeError: Cannot read property 'sqlTable' of undefined

OR

{
	"errors": [
		{
			"message": "Cannot read property 'sqlTable' of undefined",
			"locations": [
				{
					"line": 2,
					"column": 2
				}
			],
			"path": [
				"orders"
			]
		}
	],
	"data": {
		"orders": null
	}
}

Here is my code

const Order =  new graphql.GraphQLObjectType({
    name    : "Order",
    sqlTable: `order`,
    uniqueKey: "id",
    fields  : () => ({
        order_id    : {
            type: graphql.GraphQLString,
        },
    }),
});

module.exports = new graphql.GraphQLSchema({
    query : new graphql.GraphQLObjectType({
        name    : "Query",
        fields  : () => ({
            orders: {
                type    : Order,
                resolve :(obj, args, context, resolveInfo) => {
                    return join_monster(resolveInfo, context, sql => {
                        return pg.query(sql);
                    });
                },
            },
        }),
    }),
});

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
naturalethiccommented, Sep 24, 2018

@zhorzhz Can you please re-open this.

I looked into the graphql code for the new version and they no longer expose type._typeConfig after the type is constructed. Here’s a temporary work-around until the join-monster developers can deal with this in a better way.

Originally your code would have looked something like this:

const User = new gql.GraphQLObjectType({
  name: 'User',
  sqlTable: 'user',
  uniqueKey: 'id'
  fields: () => ({
    id: {
      type: gql.GraphQLInt
    }
  })
})

The fix is to now only define the graphql specific properties in the type constructor, then provide the join-monster properties afterward like so:

const User = new gql.GraphQLObjectType({
  name: 'User',
  fields: () => ({
    id: {
      type: gql.GraphQLInt
    }
  })
})

User._typeConfig = {
  sqlTable: 'user',
  uniqueKey: 'id'
}
3reactions
wthocommented, Nov 29, 2018

@s97712 yeah, that is why I used the original object.

Another way how your solution should work would be to name the class the same (untested):

import { GraphQLObjectType as OriginalGraphQLObjectType } from 'graphql';
export class GraphQLObjectType extends OriginalGraphQLObjectType {
  // ...
}

I personally prefer duck typing over constructor name comparison, but it is clearly more efficient to just check the constructor name. Maybe the maintainers are open for a PR to change this (for more extensibility). Let us know in case you read this :bowtie:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'sqlTable' of undefined #352 - GitHub
I looked into the graphql code for the new version and they no longer expose type._typeConfig after the type is constructed. Here's a...
Read more >
MEAN-Stack - Cannot read property 'map' of undefined
You're returning an object which has a property 'retrievedTables' from the server but on the client you are trying to access 'tables' which ......
Read more >
Uncaught TypeError: Cannot read property 'type' of undefined
Hello All. For the life of me I'm unable to determine what is causing this issue. The datatable is fed via ajax, and...
Read more >
TypeError: Cannot read properties of undefined (reading ...
Hello, It seems that my Azure Data Factory DataFlow began acting strange. First, I am trying to publish recent changes.
Read more >
node-mssql | Microsoft SQL Server client for Node.js
e.g. Column names cannot be passed/set in statements using variables. ... On top of the extra options, an authentication property can be added...
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