Skip to content

Commit 264fb44

Browse files
committed
fix(info): always add rootfield to info object
The rootfield wasn't added to the info object if it is a scalas type. Closes #24
1 parent 926b603 commit 264fb44

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/info.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ test('buildInfoForAllScalars: minimal static root field', t => {
8080
}
8181
`)
8282
const info = buildInfoForAllScalars('count', schema, 'query')
83-
t.is(info.fieldNodes.length, 0)
83+
t.is(info.fieldNodes.length, 1)
8484
})
8585

8686
test('buildInfoForAllScalars: mutation', t => {

src/info.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ export function buildInfoForAllScalars(
3232
const fieldNodes: FieldNode[] = []
3333
const type = getTypeForRootFieldName(rootFieldName, operation, schema)
3434

35+
let selections: FieldNode[] | undefined
3536
if (type instanceof GraphQLObjectType) {
3637
const fields = type.getFields()
37-
const selections = Object.keys(fields)
38+
selections = Object.keys(fields)
3839
.filter(f => isScalar(fields[f].type))
3940
.map<FieldNode>(fieldName => {
4041
const field = fields[fieldName]
@@ -43,15 +44,16 @@ export function buildInfoForAllScalars(
4344
name: { kind: 'Name', value: field.name },
4445
}
4546
})
46-
const fieldNode: FieldNode = {
47-
kind: 'Field',
48-
name: { kind: 'Name', value: rootFieldName },
49-
selectionSet: { kind: 'SelectionSet', selections },
50-
}
47+
}
5148

52-
fieldNodes.push(fieldNode)
49+
const fieldNode: FieldNode = {
50+
kind: 'Field',
51+
name: { kind: 'Name', value: rootFieldName },
52+
selectionSet: selections ? { kind: 'SelectionSet', selections } : undefined,
5353
}
5454

55+
fieldNodes.push(fieldNode)
56+
5557
const parentType = {
5658
query: () => schema.getQueryType(),
5759
mutation: () => schema.getMutationType()!,

0 commit comments

Comments
 (0)