Skip to content
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

#436

Closed

#436

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/query-ast-to-sql-ast/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,20 @@ 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why move these around?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because fieldConfig.sqlDeps usually has field.resolve set and didn't match fieldConfig.sqlColumn || !field.resolve condition.
Now field.resolve is always set so fieldConfig.sqlDeps need higher priority.

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, #3988)
} else if (fieldConfig.sqlColumn || parentTypeNode.constructor.name === 'GraphQLObjectType') {
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