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 264fb44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test('buildInfoForAllScalars: minimal static root field', t => {
}
`)
const info = buildInfoForAllScalars('count', schema, 'query')
t.is(info.fieldNodes.length, 0)
t.is(info.fieldNodes.length, 1)
})

test('buildInfoForAllScalars: mutation', t => {
Expand Down
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 264fb44

Please sign in to comment.