buildASTSchema.d.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import Maybe from '../tsutils/Maybe';
  2. import {
  3. DocumentNode,
  4. Location,
  5. StringValueNode,
  6. TypeDefinitionNode,
  7. NamedTypeNode,
  8. DirectiveDefinitionNode,
  9. FieldDefinitionNode,
  10. InputValueDefinitionNode,
  11. EnumValueDefinitionNode,
  12. TypeNode,
  13. } from '../language/ast';
  14. import {
  15. GraphQLNamedType,
  16. GraphQLFieldConfig,
  17. GraphQLInputField,
  18. GraphQLEnumValueConfig,
  19. GraphQLType,
  20. GraphQLArgumentConfig,
  21. GraphQLInputFieldConfig,
  22. } from '../type/definition';
  23. import { GraphQLDirective } from '../type/directives';
  24. import { Source } from '../language/source';
  25. import { GraphQLSchema, GraphQLSchemaValidationOptions } from '../type/schema';
  26. import { ParseOptions } from '../language/parser';
  27. import { dedentBlockStringValue } from '../language/blockString';
  28. interface BuildSchemaOptions extends GraphQLSchemaValidationOptions {
  29. /**
  30. * Descriptions are defined as preceding string literals, however an older
  31. * experimental version of the SDL supported preceding comments as
  32. * descriptions. Set to true to enable this deprecated behavior.
  33. * This option is provided to ease adoption and will be removed in v16.
  34. *
  35. * Default: false
  36. */
  37. commentDescriptions?: boolean;
  38. /**
  39. * Set to true to assume the SDL is valid.
  40. *
  41. * Default: false
  42. */
  43. assumeValidSDL?: boolean;
  44. }
  45. /**
  46. * This takes the ast of a schema document produced by the parse function in
  47. * src/language/parser.js.
  48. *
  49. * If no schema definition is provided, then it will look for types named Query
  50. * and Mutation.
  51. *
  52. * Given that AST it constructs a GraphQLSchema. The resulting schema
  53. * has no resolve methods, so execution will use default resolvers.
  54. *
  55. * Accepts options as a second argument:
  56. *
  57. * - commentDescriptions:
  58. * Provide true to use preceding comments as the description.
  59. *
  60. */
  61. export function buildASTSchema(
  62. documentAST: DocumentNode,
  63. options?: BuildSchemaOptions,
  64. ): GraphQLSchema;
  65. type TypeDefinitionsMap = { [key: string]: TypeDefinitionNode };
  66. type TypeResolver = (typeRef: NamedTypeNode) => GraphQLNamedType;
  67. export class ASTDefinitionBuilder {
  68. constructor(options: Maybe<BuildSchemaOptions>, resolveType: TypeResolver);
  69. getNamedType(node: NamedTypeNode): GraphQLNamedType;
  70. getWrappedType(node: TypeNode): GraphQLType;
  71. buildDirective(directive: DirectiveDefinitionNode): GraphQLDirective;
  72. buildField(field: FieldDefinitionNode): GraphQLFieldConfig<any, any>;
  73. buildArg(value: InputValueDefinitionNode): GraphQLArgumentConfig;
  74. buildInputField(value: InputValueDefinitionNode): GraphQLInputFieldConfig;
  75. buildEnumValue(value: EnumValueDefinitionNode): GraphQLEnumValueConfig;
  76. buildType(node: NamedTypeNode | TypeDefinitionNode): GraphQLNamedType;
  77. }
  78. /**
  79. * Given an ast node, returns its string description.
  80. * @deprecated: provided to ease adoption and will be removed in v16.
  81. *
  82. * Accepts options as a second argument:
  83. *
  84. * - commentDescriptions:
  85. * Provide true to use preceding comments as the description.
  86. *
  87. */
  88. export function getDescription(
  89. node: { readonly description?: StringValueNode; readonly loc?: Location },
  90. options: Maybe<BuildSchemaOptions>,
  91. ): string | undefined;
  92. /**
  93. * A helper function to build a GraphQLSchema directly from a source
  94. * document.
  95. */
  96. export function buildSchema(
  97. source: string | Source,
  98. options?: BuildSchemaOptions & ParseOptions,
  99. ): GraphQLSchema;