Skip to content

Commit

Permalink
fix(info): always add rootfield to info object
Browse files Browse the repository at this point in the history
The rootfield wasn't added to the info object if it is a scalas type.

Closes #24
  • Loading branch information
kbrandwijk committed Jan 12, 2018
1 parent 926b603 commit 764167e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ export function buildInfoForAllScalars(
const fieldNodes: FieldNode[] = []
const type = getTypeForRootFieldName(rootFieldName, operation, schema)

let selections: FieldNode[] | undefined
if (type instanceof GraphQLObjectType) {
const fields = type.getFields()
const selections = Object.keys(fields)
selections = Object.keys(fields)
.filter(f => isScalar(fields[f].type))
.map<FieldNode>(fieldName => {
const field = fields[fieldName]
Expand All @@ -43,15 +44,16 @@ export function buildInfoForAllScalars(
name: { kind: 'Name', value: field.name },
}
})
const fieldNode: FieldNode = {
kind: 'Field',
name: { kind: 'Name', value: rootFieldName },
selectionSet: { kind: 'SelectionSet', selections },
}
}

fieldNodes.push(fieldNode)
const fieldNode: FieldNode = {
kind: 'Field',
name: { kind: 'Name', value: rootFieldName },
selectionSet: selections ? { kind: 'SelectionSet', selections } : undefined,
}

fieldNodes.push(fieldNode)

const parentType = {
query: () => schema.getQueryType(),
mutation: () => schema.getMutationType()!,
Expand Down

0 comments on commit 764167e

Please sign in to comment.