introspectionQuery.js.flow 6.3 KB

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