Skip to content

Commit

Permalink
Fix apollo-server null issue due to missing columns
Browse files Browse the repository at this point in the history
Recent apollo-server-core changes always define a field resolver (see the enablePluginsForSchemaResolvers function, apollo-server issue #3988) so '!field.resolve' is not a good check for columns. Instead use parentTypeNode.constructor.name.

Incremented release version and updated change log.
  • Loading branch information
zachrdz committed Apr 30, 2021
1 parent bbf368d commit 7994cb1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
@@ -1,3 +1,9 @@
### v3.0.2 (April 4, 2021)

#### Fixed

- Fix apollo-server null issue due to missing columns [#444](https://github.com/join-monster/join-monster/pull/444)

### v3.0.0

**Breaking changes:**
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "join-monster",
"version": "3.0.1",
"version": "3.0.2",
"description": "A GraphQL to SQL query execution layer for batch data fetching.",
"main": "dist/index.js",
"engines": {
Expand Down
17 changes: 10 additions & 7 deletions src/query-ast-to-sql-ast/index.js
Expand Up @@ -235,20 +235,23 @@ export function populateASTNode(
aliasFrom += '@' + parentTypeNode.name
}
sqlASTNode.as = namespace.generate('column', aliasFrom)
// is it just a column? if they specified a sqlColumn or they didn't define a resolver, yeah
} else if (fieldConfig.sqlColumn || !field.resolve) {
// or maybe it just depends on some SQL columns
} else if (fieldConfig.sqlDeps) {
sqlASTNode.type = 'columnDeps'
sqlASTNode.names = fieldConfig.sqlDeps
// is it just a column? if they specified a sqlColumn or parentTypeNode is a GraphQLObjectType, yeah
// recent apollo-server-core always define a field resolver
// see enablePluginsForSchemaResolvers function: apollo-server issue #3988)
} else if (fieldConfig.sqlColumn ||
['GraphQLObjectType', 'GraphQLInterfaceType'].includes(parentTypeNode.constructor.name)
) {
sqlASTNode.type = 'column'
sqlASTNode.name = fieldConfig.sqlColumn || field.name
let aliasFrom = (sqlASTNode.fieldName = field.name)
if (sqlASTNode.defferedFrom) {
aliasFrom += '@' + parentTypeNode.name
}
sqlASTNode.as = namespace.generate('column', aliasFrom)
// or maybe it just depends on some SQL columns
} else if (fieldConfig.sqlDeps) {
sqlASTNode.type = 'columnDeps'
sqlASTNode.names = fieldConfig.sqlDeps
// maybe this node wants no business with your SQL, because it has its own resolver
} else {
sqlASTNode.type = 'noop'
}
Expand Down
5 changes: 5 additions & 0 deletions test-api/schema-basic/User.js
Expand Up @@ -247,6 +247,11 @@ const User = new GraphQLObjectType({
},
favNums: {
type: new GraphQLList(GraphQLInt),
extensions: {
joinMonster: {
ignoreAll: true
}
},
resolve: () => [1, 2, 3]
},
numLegs: {
Expand Down

0 comments on commit 7994cb1

Please sign in to comment.