getIntrospectionQuery.js.flow 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. // @flow strict
  2. import type { DirectiveLocationEnum } from '../language/directiveLocation';
  3. export type IntrospectionOptions = {|
  4. // Whether to include descriptions in the introspection result.
  5. // Default: true
  6. descriptions?: boolean,
  7. // Whether to include `specifiedByUrl` in the introspection result.
  8. // Default: false
  9. specifiedByUrl?: boolean,
  10. // Whether to include `isRepeatable` field on directives.
  11. // Default: false
  12. directiveIsRepeatable?: boolean,
  13. // Whether to include `description` field on schema.
  14. // Default: false
  15. schemaDescription?: boolean,
  16. |};
  17. export function getIntrospectionQuery(options?: IntrospectionOptions): string {
  18. const optionsWithDefault = {
  19. descriptions: true,
  20. specifiedByUrl: false,
  21. directiveIsRepeatable: false,
  22. schemaDescription: false,
  23. ...options,
  24. };
  25. const descriptions = optionsWithDefault.descriptions ? 'description' : '';
  26. const specifiedByUrl = optionsWithDefault.specifiedByUrl
  27. ? 'specifiedByUrl'
  28. : '';
  29. const directiveIsRepeatable = optionsWithDefault.directiveIsRepeatable
  30. ? 'isRepeatable'
  31. : '';
  32. const schemaDescription = optionsWithDefault.schemaDescription
  33. ? descriptions
  34. : '';
  35. return `
  36. query IntrospectionQuery {
  37. __schema {
  38. ${schemaDescription}
  39. queryType { name }
  40. mutationType { name }
  41. subscriptionType { name }
  42. types {
  43. ...FullType
  44. }
  45. directives {
  46. name
  47. ${descriptions}
  48. ${directiveIsRepeatable}
  49. locations
  50. args {
  51. ...InputValue
  52. }
  53. }
  54. }
  55. }
  56. fragment FullType on __Type {
  57. kind
  58. name
  59. ${descriptions}
  60. ${specifiedByUrl}
  61. fields(includeDeprecated: true) {
  62. name
  63. ${descriptions}
  64. args {
  65. ...InputValue
  66. }
  67. type {
  68. ...TypeRef
  69. }
  70. isDeprecated
  71. deprecationReason
  72. }
  73. inputFields {
  74. ...InputValue
  75. }
  76. interfaces {
  77. ...TypeRef
  78. }
  79. enumValues(includeDeprecated: true) {
  80. name
  81. ${descriptions}
  82. isDeprecated
  83. deprecationReason
  84. }
  85. possibleTypes {
  86. ...TypeRef
  87. }
  88. }
  89. fragment InputValue on __InputValue {
  90. name
  91. ${descriptions}
  92. type { ...TypeRef }
  93. defaultValue
  94. }
  95. fragment TypeRef on __Type {
  96. kind
  97. name
  98. ofType {
  99. kind
  100. name
  101. ofType {
  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. }
  120. }
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. `;
  128. }
  129. export type IntrospectionQuery = {|
  130. +__schema: IntrospectionSchema,
  131. |};
  132. export type IntrospectionSchema = {|
  133. +description?: ?string,
  134. +queryType: IntrospectionNamedTypeRef<IntrospectionObjectType>,
  135. +mutationType: ?IntrospectionNamedTypeRef<IntrospectionObjectType>,
  136. +subscriptionType: ?IntrospectionNamedTypeRef<IntrospectionObjectType>,
  137. +types: $ReadOnlyArray<IntrospectionType>,
  138. +directives: $ReadOnlyArray<IntrospectionDirective>,
  139. |};
  140. export type IntrospectionType =
  141. | IntrospectionScalarType
  142. | IntrospectionObjectType
  143. | IntrospectionInterfaceType
  144. | IntrospectionUnionType
  145. | IntrospectionEnumType
  146. | IntrospectionInputObjectType;
  147. export type IntrospectionOutputType =
  148. | IntrospectionScalarType
  149. | IntrospectionObjectType
  150. | IntrospectionInterfaceType
  151. | IntrospectionUnionType
  152. | IntrospectionEnumType;
  153. export type IntrospectionInputType =
  154. | IntrospectionScalarType
  155. | IntrospectionEnumType
  156. | IntrospectionInputObjectType;
  157. export type IntrospectionScalarType = {|
  158. +kind: 'SCALAR',
  159. +name: string,
  160. +description?: ?string,
  161. +specifiedByUrl: ?string,
  162. |};
  163. export type IntrospectionObjectType = {|
  164. +kind: 'OBJECT',
  165. +name: string,
  166. +description?: ?string,
  167. +fields: $ReadOnlyArray<IntrospectionField>,
  168. +interfaces: $ReadOnlyArray<
  169. IntrospectionNamedTypeRef<IntrospectionInterfaceType>,
  170. >,
  171. |};
  172. export type IntrospectionInterfaceType = {|
  173. +kind: 'INTERFACE',
  174. +name: string,
  175. +description?: ?string,
  176. +fields: $ReadOnlyArray<IntrospectionField>,
  177. +interfaces: $ReadOnlyArray<
  178. IntrospectionNamedTypeRef<IntrospectionInterfaceType>,
  179. >,
  180. +possibleTypes: $ReadOnlyArray<
  181. IntrospectionNamedTypeRef<IntrospectionObjectType>,
  182. >,
  183. |};
  184. export type IntrospectionUnionType = {|
  185. +kind: 'UNION',
  186. +name: string,
  187. +description?: ?string,
  188. +possibleTypes: $ReadOnlyArray<
  189. IntrospectionNamedTypeRef<IntrospectionObjectType>,
  190. >,
  191. |};
  192. export type IntrospectionEnumType = {|
  193. +kind: 'ENUM',
  194. +name: string,
  195. +description?: ?string,
  196. +enumValues: $ReadOnlyArray<IntrospectionEnumValue>,
  197. |};
  198. export type IntrospectionInputObjectType = {|
  199. +kind: 'INPUT_OBJECT',
  200. +name: string,
  201. +description?: ?string,
  202. +inputFields: $ReadOnlyArray<IntrospectionInputValue>,
  203. |};
  204. export type IntrospectionListTypeRef<
  205. T: IntrospectionTypeRef = IntrospectionTypeRef,
  206. > = {|
  207. +kind: 'LIST',
  208. +ofType: T,
  209. |};
  210. export type IntrospectionNonNullTypeRef<
  211. T: IntrospectionTypeRef = IntrospectionTypeRef,
  212. > = {|
  213. +kind: 'NON_NULL',
  214. +ofType: T,
  215. |};
  216. export type IntrospectionTypeRef =
  217. | IntrospectionNamedTypeRef<>
  218. | IntrospectionListTypeRef<>
  219. | IntrospectionNonNullTypeRef<
  220. IntrospectionNamedTypeRef<> | IntrospectionListTypeRef<>,
  221. >;
  222. export type IntrospectionOutputTypeRef =
  223. | IntrospectionNamedTypeRef<IntrospectionOutputType>
  224. | IntrospectionListTypeRef<IntrospectionOutputTypeRef>
  225. | IntrospectionNonNullTypeRef<
  226. | IntrospectionNamedTypeRef<IntrospectionOutputType>
  227. | IntrospectionListTypeRef<IntrospectionOutputTypeRef>,
  228. >;
  229. export type IntrospectionInputTypeRef =
  230. | IntrospectionNamedTypeRef<IntrospectionInputType>
  231. | IntrospectionListTypeRef<IntrospectionInputTypeRef>
  232. | IntrospectionNonNullTypeRef<
  233. | IntrospectionNamedTypeRef<IntrospectionInputType>
  234. | IntrospectionListTypeRef<IntrospectionInputTypeRef>,
  235. >;
  236. export type IntrospectionNamedTypeRef<
  237. T: IntrospectionType = IntrospectionType,
  238. > = {|
  239. +kind: $PropertyType<T, 'kind'>,
  240. +name: string,
  241. |};
  242. export type IntrospectionField = {|
  243. +name: string,
  244. +description?: ?string,
  245. +args: $ReadOnlyArray<IntrospectionInputValue>,
  246. +type: IntrospectionOutputTypeRef,
  247. +isDeprecated: boolean,
  248. +deprecationReason: ?string,
  249. |};
  250. export type IntrospectionInputValue = {|
  251. +name: string,
  252. +description?: ?string,
  253. +type: IntrospectionInputTypeRef,
  254. +defaultValue: ?string,
  255. |};
  256. export type IntrospectionEnumValue = {|
  257. +name: string,
  258. +description?: ?string,
  259. +isDeprecated: boolean,
  260. +deprecationReason: ?string,
  261. |};
  262. export type IntrospectionDirective = {|
  263. +name: string,
  264. +description?: ?string,
  265. +isRepeatable?: boolean,
  266. +locations: $ReadOnlyArray<DirectiveLocationEnum>,
  267. +args: $ReadOnlyArray<IntrospectionInputValue>,
  268. |};