getIntrospectionQuery.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true,
  4. });
  5. exports.getIntrospectionQuery = getIntrospectionQuery;
  6. /**
  7. * Produce the GraphQL query recommended for a full schema introspection.
  8. * Accepts optional IntrospectionOptions.
  9. */
  10. function getIntrospectionQuery(options) {
  11. const optionsWithDefault = {
  12. descriptions: true,
  13. specifiedByUrl: false,
  14. directiveIsRepeatable: false,
  15. schemaDescription: false,
  16. inputValueDeprecation: false,
  17. ...options,
  18. };
  19. const descriptions = optionsWithDefault.descriptions ? 'description' : '';
  20. const specifiedByUrl = optionsWithDefault.specifiedByUrl
  21. ? 'specifiedByURL'
  22. : '';
  23. const directiveIsRepeatable = optionsWithDefault.directiveIsRepeatable
  24. ? 'isRepeatable'
  25. : '';
  26. const schemaDescription = optionsWithDefault.schemaDescription
  27. ? descriptions
  28. : '';
  29. function inputDeprecation(str) {
  30. return optionsWithDefault.inputValueDeprecation ? str : '';
  31. }
  32. return `
  33. query IntrospectionQuery {
  34. __schema {
  35. ${schemaDescription}
  36. queryType { name }
  37. mutationType { name }
  38. subscriptionType { name }
  39. types {
  40. ...FullType
  41. }
  42. directives {
  43. name
  44. ${descriptions}
  45. ${directiveIsRepeatable}
  46. locations
  47. args${inputDeprecation('(includeDeprecated: true)')} {
  48. ...InputValue
  49. }
  50. }
  51. }
  52. }
  53. fragment FullType on __Type {
  54. kind
  55. name
  56. ${descriptions}
  57. ${specifiedByUrl}
  58. fields(includeDeprecated: true) {
  59. name
  60. ${descriptions}
  61. args${inputDeprecation('(includeDeprecated: true)')} {
  62. ...InputValue
  63. }
  64. type {
  65. ...TypeRef
  66. }
  67. isDeprecated
  68. deprecationReason
  69. }
  70. inputFields${inputDeprecation('(includeDeprecated: true)')} {
  71. ...InputValue
  72. }
  73. interfaces {
  74. ...TypeRef
  75. }
  76. enumValues(includeDeprecated: true) {
  77. name
  78. ${descriptions}
  79. isDeprecated
  80. deprecationReason
  81. }
  82. possibleTypes {
  83. ...TypeRef
  84. }
  85. }
  86. fragment InputValue on __InputValue {
  87. name
  88. ${descriptions}
  89. type { ...TypeRef }
  90. defaultValue
  91. ${inputDeprecation('isDeprecated')}
  92. ${inputDeprecation('deprecationReason')}
  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. }