New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot read property 'sqlTable' of undefined #352
Comments
sqlTable
As mentioned here: This is due incompatibility with graphql 14. Just install the older version:
|
Thanks, @naturalethic. Is there any chance that new versions of join-monster will be compatible with the latest graphql versions. |
@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:
The fix is to now only define the graphql specific properties in the type constructor, then provide the join-monster properties afterward like so:
|
@naturalethic Thanks a lot. I will try it. Seems it can solve our issue, but of course it would be great if |
This feature might be useful also for join-monster: graphql/graphql-js#1527 |
That seems appropriate. |
I can also confirm this issue. @naturalethic 's work-around resolved this for me. |
This is quality info, thanks for the leg work and concise summary @naturalethic |
Reading the issue over at graphql-js I see no other way forward than proposed: adding an |
Here's a function which encapsulates the fix proposed by @naturalethic, so less changes have to be made: function newJoinMonsterGraphQLObjectType(objectTypeConfig) {
const joinMonsterConfig = {}
const joinMonsterKeys = ['sqlTable', 'uniqueKey', 'alwaysFetch']
joinMonsterKeys.forEach(key => {
if (key in objectTypeConfig) {
joinMonsterConfig[key] = objectTypeConfig[key]
}
})
const GraphQLObject = new GraphQLObjectType(objectTypeConfig)
GraphQLObject._typeConfig = joinMonsterConfig
return GraphQLObject
} You can use it like this:Before (graphql version < 14) const User = new gql.GraphQLObjectType({
name: 'User',
sqlTable: 'users',
uniqueKey: 'id',
fields: () => ({
...
})
}) After (graphql v14) const User = newJoinMonsterGraphQLObjectType({
name: 'User',
sqlTable: 'users',
uniqueKey: 'id',
fields: () => ({
...
})
}) Check out the Typescript version if you prefer that. I also had to patch objects not directly tied to a sql table, as join monster would check them anyway and run in a ReadOfUndefined-Error, assuming the |
To what @wtho said, if you want to get this working without any changes with graphql-tools, I submitted a work around here join-monster/join-monster-graphql-tools-adapter#15. |
@flipxfx Awesome! |
May be we can through inherit |
@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. |
Doesn't seem like a bad plan, but personally I prefer waiting what the upstream graphql-js answer is to this problem. If we change our API now, and then upstream changes its mind, it will be work for nothing. |
Yeah, totally agree! Let's wait and react once the graphql-js API is updated. |
@GlennMatthys GraphQL added the ability to pass extra metadata via extensions! |
Is anyone working on a PR to upgrade |
@airhorns a POC PR would certainly be welcome. No one on the core team has started work on this yet. |
We just released support for graphql@15 in https://join-monster.readthedocs.io/en/latest/map-to-table/ const User = new GraphQLObjectType({
name: 'User',
extensions: {
joinMonster: {
sqlTable: 'accounts', // the SQL table for this object type is called "accounts"
uniqueKey: 'id' // id is different for every row
}
},
fields: () => ({
/*...*/
})
}) |
Join-monster fails with
OR
Here is my code
The text was updated successfully, but these errors were encountered: