Skip to content

Commit

Permalink
move trying to infer Files from string paths to inferGraphQLType func…
Browse files Browse the repository at this point in the history
…tion where rest of value based inferring is done
  • Loading branch information
pieh committed Jan 28, 2018
1 parent 6112cc1 commit 5bb3da5
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/gatsby/src/schema/infer-graphql-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,21 @@ export type ProcessedNodeType = {
function inferGraphQLType({
exampleValue,
selector,
nodes,
types,
...otherArgs
}): ?GraphQLFieldConfig<*, *> {
if (exampleValue == null || isEmptyObjectOrArray(exampleValue)) return null
let fieldName = selector.split(`.`).pop()

// Check this before checking for array as FileType has
// builtin support for inferring array of files and inferred
// array type will have faster resolver than resolving array
// of files separately.
if (FileType.shouldInfer(nodes, selector, exampleValue)) {
return _.isArray(exampleValue) ? FileType.getListType() : FileType.getType()
}

if (Array.isArray(exampleValue)) {
exampleValue = exampleValue[0]

Expand All @@ -54,6 +64,8 @@ function inferGraphQLType({
...otherArgs,
exampleValue,
selector,
nodes,
types,
})
invariant(
inferredType,
Expand Down Expand Up @@ -100,6 +112,8 @@ function inferGraphQLType({
...otherArgs,
exampleValue,
selector,
nodes,
types,
}),
}),
}
Expand Down Expand Up @@ -329,13 +343,6 @@ export function inferObjectStructureFromNodes({
} else if (_.includes(key, `___NODE`)) {
;[fieldName] = key.split(`___`)
inferredField = inferFromFieldName(value, nextSelector, types)

// Third if the field (whether a string or array of string(s)) is
// pointing to a file (from another file).
} else if (FileType.shouldInfer(nodes, nextSelector, value)) {
inferredField = _.isArray(value)
? FileType.getListType()
: FileType.getType()
}

// Finally our automatic inference of field value type.
Expand Down

0 comments on commit 5bb3da5

Please sign in to comment.