-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathinfo.ts
52 lines (48 loc) · 1.16 KB
/
info.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {
GraphQLResolveInfo,
FieldNode,
GraphQLSchema,
isListType,
isNonNullType,
} from 'graphql'
export function buildExistsInfo(
rootFieldName: string,
schema: GraphQLSchema,
): GraphQLResolveInfo {
const queryType = schema.getQueryType() || undefined!
const type = queryType.getFields()[rootFieldName].type
// make sure that just list types are queried
if (!isNonNullType(type) || !isListType(type.ofType)) {
throw new Error(`Invalid exist query: ${rootFieldName}`)
}
const fieldNode: FieldNode = {
kind: 'Field',
name: { kind: 'Name', value: rootFieldName },
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'id' },
},
],
},
}
return {
fieldNodes: [fieldNode],
fragments: {},
schema,
fieldName: rootFieldName,
returnType: type,
parentType: queryType,
path: undefined!,
rootValue: null,
operation: {
kind: 'OperationDefinition',
operation: 'query',
selectionSet: { kind: 'SelectionSet', selections: [] },
variableDefinitions: [],
},
variableValues: {},
}
}