UNPKG

3.04 kBJavaScriptView Raw
1/**
2 * Produce the GraphQL query recommended for a full schema introspection.
3 * Accepts optional IntrospectionOptions.
4 */
5export function getIntrospectionQuery(options) {
6 const optionsWithDefault = {
7 descriptions: true,
8 specifiedByUrl: false,
9 directiveIsRepeatable: false,
10 schemaDescription: false,
11 inputValueDeprecation: false,
12 ...options,
13 };
14 const descriptions = optionsWithDefault.descriptions ? 'description' : '';
15 const specifiedByUrl = optionsWithDefault.specifiedByUrl
16 ? 'specifiedByURL'
17 : '';
18 const directiveIsRepeatable = optionsWithDefault.directiveIsRepeatable
19 ? 'isRepeatable'
20 : '';
21 const schemaDescription = optionsWithDefault.schemaDescription
22 ? descriptions
23 : '';
24
25 function inputDeprecation(str) {
26 return optionsWithDefault.inputValueDeprecation ? str : '';
27 }
28
29 return `
30 query IntrospectionQuery {
31 __schema {
32 ${schemaDescription}
33 queryType { name }
34 mutationType { name }
35 subscriptionType { name }
36 types {
37 ...FullType
38 }
39 directives {
40 name
41 ${descriptions}
42 ${directiveIsRepeatable}
43 locations
44 args${inputDeprecation('(includeDeprecated: true)')} {
45 ...InputValue
46 }
47 }
48 }
49 }
50
51 fragment FullType on __Type {
52 kind
53 name
54 ${descriptions}
55 ${specifiedByUrl}
56 fields(includeDeprecated: true) {
57 name
58 ${descriptions}
59 args${inputDeprecation('(includeDeprecated: true)')} {
60 ...InputValue
61 }
62 type {
63 ...TypeRef
64 }
65 isDeprecated
66 deprecationReason
67 }
68 inputFields${inputDeprecation('(includeDeprecated: true)')} {
69 ...InputValue
70 }
71 interfaces {
72 ...TypeRef
73 }
74 enumValues(includeDeprecated: true) {
75 name
76 ${descriptions}
77 isDeprecated
78 deprecationReason
79 }
80 possibleTypes {
81 ...TypeRef
82 }
83 }
84
85 fragment InputValue on __InputValue {
86 name
87 ${descriptions}
88 type { ...TypeRef }
89 defaultValue
90 ${inputDeprecation('isDeprecated')}
91 ${inputDeprecation('deprecationReason')}
92 }
93
94 fragment TypeRef on __Type {
95 kind
96 name
97 ofType {
98 kind
99 name
100 ofType {
101 kind
102 name
103 ofType {
104 kind
105 name
106 ofType {
107 kind
108 name
109 ofType {
110 kind
111 name
112 ofType {
113 kind
114 name
115 ofType {
116 kind
117 name
118 ofType {
119 kind
120 name
121 ofType {
122 kind
123 name
124 }
125 }
126 }
127 }
128 }
129 }
130 }
131 }
132 }
133 }
134 `;
135}