-
Notifications
You must be signed in to change notification settings - Fork 116
/
index.js
95 lines (92 loc) · 2.77 KB
/
index.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import get from 'lodash/get'
import sortBy from 'lodash/sortBy'
import { Microfiber as IntrospectionManipulator } from 'microfiber'
export default ({
introspectionResponse,
graphQLSchema: _graphQLSchema,
allOptions: _allOptions,
introspectionOptions,
}) => {
const introspectionManipulator = new IntrospectionManipulator(
introspectionResponse,
introspectionOptions?.microfiberOptions
)
const queryType = introspectionManipulator.getQueryType()
const mutationType = introspectionManipulator.getMutationType()
const subscriptionType = introspectionManipulator.getSubscriptionType()
const otherTypes = introspectionManipulator.getAllTypes({
includeQuery: false,
includeMutation: false,
includeSubscription: false,
})
const hasQueries = get(queryType, 'fields.length')
const hasMutations = get(mutationType, 'fields.length')
const hasQueriesOrMutations = hasQueries || hasMutations
const hasSubscriptions = get(subscriptionType, 'fields.length')
const hasOtherTypes = get(otherTypes, 'length')
return [
hasQueriesOrMutations
? {
name: 'Operations',
hideInContent: true,
items: [
hasQueries
? {
name: 'Queries',
makeNavSection: true,
makeContentSection: true,
items: sortBy(
queryType.fields.map((query) => ({
...query,
isQuery: true,
})),
'name'
),
}
: null,
hasMutations
? {
name: 'Mutations',
makeNavSection: true,
makeContentSection: true,
items: sortBy(
mutationType.fields.map((query) => ({
...query,
isMutation: true,
})),
'name'
),
}
: null,
hasSubscriptions
? {
name: 'Subscriptions',
makeNavSection: true,
makeContentSection: true,
items: sortBy(
subscriptionType.fields.map((type) => ({
...type,
isSubscription: true,
})),
'name'
),
}
: null,
],
}
: null,
hasOtherTypes
? {
name: 'Types',
makeContentSection: true,
items: sortBy(
otherTypes.map((type) => ({
...type,
isType: true,
})),
'name'
),
}
: null,
].filter(Boolean)
}