Skip to content

Commit

Permalink
fix: check for INVALID_VALUE to avoid throwing exceptions on bad data (
Browse files Browse the repository at this point in the history
…#8346)

* check for symbol values to avoid throwing exceptions on bad data
throwing error `TypeError: Cannot read property 'internal' of null`

* check directly for INVALID_VALUE
  • Loading branch information
zanedev authored and pieh committed Sep 24, 2018
1 parent 073711a commit bb5c0d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/gatsby/src/schema/infer-graphql-input-fields.js
Expand Up @@ -17,6 +17,7 @@ const {
getExampleValues,
extractFieldNames,
isEmptyObjectOrArray,
INVALID_VALUE,
} = require(`./data-tree-utils`)

const { findLinkedNode } = require(`./infer-graphql-type`)
Expand Down Expand Up @@ -264,7 +265,7 @@ export function inferInputObjectStructureFromNodes({
let key = k
// Remove fields for traversing through nodes as we want to control
// setting traversing up not try to automatically infer them.
if (isRoot && EXCLUDE_KEYS[key]) return
if (value === INVALID_VALUE || (isRoot && EXCLUDE_KEYS[key])) return

if (_.includes(key, `___NODE`)) {
// TODO: Union the objects in array
Expand Down
8 changes: 6 additions & 2 deletions packages/gatsby/src/schema/infer-graphql-type.js
Expand Up @@ -16,7 +16,11 @@ const { store, getNode, getNodes } = require(`../redux`)
const { createPageDependency } = require(`../redux/actions/add-page-dependency`)
const createTypeName = require(`./create-type-name`)
const createKey = require(`./create-key`)
const { getExampleValues, isEmptyObjectOrArray } = require(`./data-tree-utils`)
const {
getExampleValues,
isEmptyObjectOrArray,
INVALID_VALUE,
} = require(`./data-tree-utils`)
const DateType = require(`./types/type-date`)
const FileType = require(`./types/type-file`)
const is32BitInteger = require(`../utils/is-32-bit-integer`)
Expand Down Expand Up @@ -341,7 +345,7 @@ function _inferObjectStructureFromNodes(
_.each(resolvedExample, (value, key) => {
// Remove fields common to the top-level of all nodes. We add these
// elsewhere so don't need to infer their type.
if (isRoot && EXCLUDE_KEYS[key]) return
if (value === INVALID_VALUE || (isRoot && EXCLUDE_KEYS[key])) return

// Several checks to see if a field is pointing to custom type
// before we try automatic inference.
Expand Down

0 comments on commit bb5c0d2

Please sign in to comment.