getIntrospectionQuery.mjs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * Produce the GraphQL query recommended for a full schema introspection.
  3. * Accepts optional IntrospectionOptions.
  4. */
  5. export 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. function inputDeprecation(str) {
  25. return optionsWithDefault.inputValueDeprecation ? str : '';
  26. }
  27. return `
  28. query IntrospectionQuery {
  29. __schema {
  30. ${schemaDescription}
  31. queryType { name }
  32. mutationType { name }
  33. subscriptionType { name }
  34. types {
  35. ...FullType
  36. }
  37. directives {
  38. name
  39. ${descriptions}
  40. ${directiveIsRepeatable}
  41. locations
  42. args${inputDeprecation('(includeDeprecated: true)')} {
  43. ...InputValue
  44. }
  45. }
  46. }
  47. }
  48. fragment FullType on __Type {
  49. kind
  50. name
  51. ${descriptions}
  52. ${specifiedByUrl}
  53. fields(includeDeprecated: true) {
  54. name
  55. ${descriptions}
  56. args${inputDeprecation('(includeDeprecated: true)')} {
  57. ...InputValue
  58. }
  59. type {
  60. ...TypeRef
  61. }
  62. isDeprecated
  63. deprecationReason
  64. }
  65. inputFields${inputDeprecation('(includeDeprecated: true)')} {
  66. ...InputValue
  67. }
  68. interfaces {
  69. ...TypeRef
  70. }
  71. enumValues(includeDeprecated: true) {
  72. name
  73. ${descriptions}
  74. isDeprecated
  75. deprecationReason
  76. }
  77. possibleTypes {
  78. ...TypeRef
  79. }
  80. }
  81. fragment InputValue on __InputValue {
  82. name
  83. ${descriptions}
  84. type { ...TypeRef }
  85. defaultValue
  86. ${inputDeprecation('isDeprecated')}
  87. ${inputDeprecation('deprecationReason')}
  88. }
  89. fragment TypeRef on __Type {
  90. kind
  91. name
  92. ofType {
  93. kind
  94. name
  95. ofType {
  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. `;
  130. }