You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our Gatsby project consumes numerous queries from our single graphql endpoint. The various queries return either an Array, or a non-iterable object. See example below:
The toolkit properly handles the queries which return iterable objects (i.e. Array). However, the toolkit fails to properly handle non-iterable objects, by throwing a TypeError. I have an extract of the error stack-trace below:
warn TypeError: partialNodes is not iterable
at fetchNodeList (/gatsby/node_modules/gatsby-graphql-source-toolkit/src/source-nodes/fetch-nodes/fetch-lists.ts:64:24)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at Object.fetchAllNodes (/gatsby/node_modules/gatsby-graphql-source-toolkit/src/source-nodes/fetch-nodes/fetch-lists.ts:36:24)
at Object.createNodes (/gatsby/node_modules/gatsby-graphql-source-toolkit/src/source-nodes/node-actions/create-nodes.ts:13:20)
at async Promise.all (index 0)
at sourceAllNodes (/gatsby/node_modules/gatsby-graphql-source-toolkit/src/source-nodes/source-all-nodes.ts:20:3)
at Object.exports.sourceNodes (/gatsby/website/plugins/gatsby-source-odunet/gatsby-node.js:69:5)
at runAPI (/gatsby/node_modules/gatsby/src/utils/api-runner-node.js:434:16)
Proposed resolution
The stack trace shows that the error is thrown in the code block below. The toolkit expects partialNodes to be iterable. It is therefore unable to handle queries that return non-iterable objects, e.g. type: LocationSettings! above.
A possible fix would introduce a conditional statement to check the partialNodes type, and properly handle it. I have a sample solution below which will replace the block of code above:
if (Array.isArray(partialNodes)) {
for (const node of partialNodes) {
if (!node || node[typeNameField] !== remoteTypeName) {
// Possible when fetching complex interface or union type fields
// or when some node is `null`
continue
}
// TODO: run in parallel?
yield addPaginatedFields(context, nodeDefinition, node)
}
} else if (partialNodes && partialNodes[typeNameField] === remoteTypeName) {
yield addPaginatedFields(context, nodeDefinition, partialNodes)
}
The text was updated successfully, but these errors were encountered:
Problem
Our Gatsby project consumes numerous queries from our single graphql endpoint. The various queries return either an Array, or a non-iterable object. See example below:
The toolkit properly handles the queries which return iterable objects (i.e. Array). However, the toolkit fails to properly handle non-iterable objects, by throwing a TypeError. I have an extract of the error stack-trace below:
Proposed resolution
The stack trace shows that the error is thrown in the code block below. The toolkit expects
partialNodes
to be iterable. It is therefore unable to handle queries that return non-iterable objects, e.g.type: LocationSettings!
above.gatsby-graphql-toolkit/src/source-nodes/fetch-nodes/fetch-lists.ts
Lines 61 to 73 in 2b705fb
A possible fix would introduce a conditional statement to check the
partialNodes
type, and properly handle it. I have a sample solution below which will replace the block of code above:The text was updated successfully, but these errors were encountered: