From 7994cb177072d5f828304afe9601767fe8c5b9e5 Mon Sep 17 00:00:00 2001 From: Zachary Rodriguez Date: Thu, 29 Apr 2021 22:51:35 -0500 Subject: [PATCH] Fix apollo-server null issue due to missing columns 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. --- docs/CHANGELOG.md | 6 ++++++ package.json | 2 +- src/query-ast-to-sql-ast/index.js | 17 ++++++++++------- test-api/schema-basic/User.js | 5 +++++ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e43d5267..2ca6c2ab 100644 --- a/docs/CHANGELOG.md +++ b/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:** diff --git a/package.json b/package.json index 3921eb7f..77feac18 100644 --- a/package.json +++ b/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": { diff --git a/src/query-ast-to-sql-ast/index.js b/src/query-ast-to-sql-ast/index.js index 8566aa82..9c2511df 100644 --- a/src/query-ast-to-sql-ast/index.js +++ b/src/query-ast-to-sql-ast/index.js @@ -235,8 +235,16 @@ 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) @@ -244,11 +252,6 @@ export function populateASTNode( 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' } diff --git a/test-api/schema-basic/User.js b/test-api/schema-basic/User.js index c0a519b7..0481e5aa 100644 --- a/test-api/schema-basic/User.js +++ b/test-api/schema-basic/User.js @@ -247,6 +247,11 @@ const User = new GraphQLObjectType({ }, favNums: { type: new GraphQLList(GraphQLInt), + extensions: { + joinMonster: { + ignoreAll: true + } + }, resolve: () => [1, 2, 3] }, numLegs: {