UNPKG

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