Skip to content

Commit

Permalink
fix bug with junctions in a batch after a union type. fix null checki…
Browse files Browse the repository at this point in the history
…ng bug in the batch planner
  • Loading branch information
Andrew Carlson committed Sep 1, 2017
1 parent b726e53 commit 23fd7ea
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "join-monster",
"version": "2.0.10",
"version": "2.0.11",
"description": "A GraphQL to SQL query execution layer for batch data fetching.",
"main": "dist/index.js",
"engines": {
Expand Down
6 changes: 3 additions & 3 deletions src/batch-planner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function nextBatch(sqlAST, data, dbCall, context, options)
}

const children = sqlAST.children
children.push(...Object.values(sqlAST.typedChildren || {}))
Object.values(sqlAST.typedChildren || {}).forEach(typedChildren => children.push(...typedChildren))

// loop through all the child fields that are tables
return Promise.all(children.map(async childAST => {
Expand Down Expand Up @@ -75,7 +75,7 @@ export default async function nextBatch(sqlAST, data, dbCall, context, options)
}

// move down a level and recurse
const nextLevelData = chain(data).filter(obj => obj !== null).flatMap(obj => obj[fieldName]).value()
const nextLevelData = chain(data).filter(obj => obj != null).flatMap(obj => obj[fieldName]).value()
return nextBatch(childAST, nextLevelData, dbCall, context, options)
}
const batchScope = [ maybeQuote(data[parentKey]) ]
Expand All @@ -97,7 +97,7 @@ export default async function nextBatch(sqlAST, data, dbCall, context, options)

// otherwise, just bypass this and recurse down to the next level
} else if (Array.isArray(data)) {
const nextLevelData = chain(data).filter(obj => obj !== null).flatMap(obj => obj[fieldName]).value()
const nextLevelData = chain(data).filter(obj => obj != null).flatMap(obj => obj[fieldName]).value()
return nextBatch(childAST, nextLevelData, dbCall, context, options)
} else if (data) {
return nextBatch(childAST, data[fieldName], dbCall, context, options)
Expand Down
3 changes: 3 additions & 0 deletions src/define-object-shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ function _defineObjectShape(parent, prefix, node) {
case 'table':
if (child.sqlBatch) {
fieldDefinition[child.sqlBatch.parentKey.fieldName + suffix] = prefixToPass + child.sqlBatch.parentKey.as
} else if (idx(child, _ => _.junction.sqlBatch)) {
fieldDefinition[child.junction.sqlBatch.parentKey.fieldName + suffix] =
prefixToPass + child.junction.sqlBatch.parentKey.as
} else {
const definition = _defineObjectShape(node, prefixToPass, child)
fieldDefinition[child.fieldName + suffix] = definition
Expand Down

0 comments on commit 23fd7ea

Please sign in to comment.