diff --git a/src/index.d.ts b/src/index.d.ts index 89e2cc33d11..afa427e1680 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -382,9 +382,6 @@ export { buildASTSchema, // Build a GraphQLSchema from a GraphQL schema language document. buildSchema, - // @deprecated: Get the description from a schema AST node and supports legacy - // syntax for specifying descriptions - will be removed in v16. - getDescription, // Extends an existing GraphQLSchema from a parsed GraphQL Schema // language AST. extendSchema, diff --git a/src/index.js b/src/index.js index e19e6084d53..873a374ba2e 100644 --- a/src/index.js +++ b/src/index.js @@ -371,9 +371,6 @@ export { buildASTSchema, // Build a GraphQLSchema from a GraphQL schema language document. buildSchema, - // @deprecated: Get the description from a schema AST node and supports legacy - // syntax for specifying descriptions - will be removed in v16. - getDescription, // Extends an existing GraphQLSchema from a parsed GraphQL Schema // language AST. extendSchema, diff --git a/src/utilities/__tests__/buildASTSchema-test.js b/src/utilities/__tests__/buildASTSchema-test.js index f364e311dd4..85d0509a5cc 100644 --- a/src/utilities/__tests__/buildASTSchema-test.js +++ b/src/utilities/__tests__/buildASTSchema-test.js @@ -47,12 +47,8 @@ import { buildASTSchema, buildSchema } from '../buildASTSchema'; * the SDL, parsed in a schema AST, materializing that schema AST into an * in-memory GraphQLSchema, and then finally printing that object into the SDL */ -function cycleSDL(sdl: string, options): string { - const ast = parse(sdl); - const schema = buildASTSchema(ast, options); - - const commentDescriptions = options?.commentDescriptions; - return printSchema(schema, { commentDescriptions }); +function cycleSDL(sdl: string): string { + return printSchema(buildSchema(sdl)); } function printASTNode(obj: ?{ +astNode: ?ASTNode, ... }): string { @@ -225,32 +221,6 @@ describe('Schema Builder', () => { expect(cycleSDL(sdl)).to.equal(sdl); }); - it('Supports option for comment descriptions', () => { - const sdl = dedent` - # This is a directive - directive @foo( - # It has an argument - arg: Int - ) on FIELD - - # With an enum - enum Color { - RED - - # Not a creative color - GREEN - BLUE - } - - # What a great type - type Query { - # And a field to boot - str: String - } - `; - expect(cycleSDL(sdl, { commentDescriptions: true })).to.equal(sdl); - }); - it('Maintains @include, @skip & @specifiedBy', () => { const schema = buildSchema('type Query'); diff --git a/src/utilities/__tests__/extendSchema-test.js b/src/utilities/__tests__/extendSchema-test.js index e898363a7c6..094713a507a 100644 --- a/src/utilities/__tests__/extendSchema-test.js +++ b/src/utilities/__tests__/extendSchema-test.js @@ -132,70 +132,6 @@ describe('extendSchema', () => { `); }); - it('can describe the extended fields with legacy comments', () => { - const schema = buildSchema('type Query'); - const extendAST = parse(` - extend type Query { - # New field description. - newField: String - } - `); - const extendedSchema = extendSchema(schema, extendAST, { - commentDescriptions: true, - }); - - expect(validateSchema(extendedSchema)).to.deep.equal([]); - expect(printSchemaChanges(schema, extendedSchema)).to.equal(dedent` - type Query { - """New field description.""" - newField: String - } - `); - }); - - it('describes extended fields with strings when present', () => { - const schema = buildSchema('type Query'); - const extendAST = parse(` - extend type Query { - # New field description. - "Actually use this description." - newField: String - } - `); - const extendedSchema = extendSchema(schema, extendAST, { - commentDescriptions: true, - }); - - expect(validateSchema(extendedSchema)).to.deep.equal([]); - expect(printSchemaChanges(schema, extendedSchema)).to.equal(dedent` - type Query { - """Actually use this description.""" - newField: String - } - `); - }); - - it('ignores comment description on extended fields if location is not provided', () => { - const schema = buildSchema('type Query'); - const extendSDL = ` - extend type Query { - # New field description. - newField: String - } - `; - const extendAST = parse(extendSDL, { noLocation: true }); - const extendedSchema = extendSchema(schema, extendAST, { - commentDescriptions: true, - }); - - expect(validateSchema(extendedSchema)).to.deep.equal([]); - expect(printSchemaChanges(schema, extendedSchema)).to.equal(dedent` - type Query { - newField: String - } - `); - }); - it('extends objects with standard type fields', () => { const schema = buildSchema('type Query'); @@ -1197,24 +1133,6 @@ describe('extendSchema', () => { expect(printSchemaChanges(schema, extendedSchema)).to.equal(extensionSDL); }); - it('sets correct description using legacy comments', () => { - const schema = buildSchema(` - type Query { - foo: String - } - `); - const extendAST = parse(` - # new directive - directive @new on QUERY - `); - const extendedSchema = extendSchema(schema, extendAST, { - commentDescriptions: true, - }); - - const newDirective = extendedSchema.getDirective('new'); - expect(newDirective).to.include({ description: 'new directive' }); - }); - it('Rejects invalid SDL', () => { const schema = new GraphQLSchema({}); const extendAST = parse('extend schema @unknown'); diff --git a/src/utilities/__tests__/printSchema-test.js b/src/utilities/__tests__/printSchema-test.js index df064c3724a..2bedc1478fb 100644 --- a/src/utilities/__tests__/printSchema-test.js +++ b/src/utilities/__tests__/printSchema-test.js @@ -832,201 +832,4 @@ describe('Type System Printer', () => { } `); }); - - it('Print Introspection Schema with comment descriptions', () => { - const schema = new GraphQLSchema({}); - const output = printIntrospectionSchema(schema, { - commentDescriptions: true, - }); - - expect(output).to.equal(dedent` - # Directs the executor to include this field or fragment only when the \`if\` argument is true. - directive @include( - # Included when true. - if: Boolean! - ) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT - - # Directs the executor to skip this field or fragment when the \`if\` argument is true. - directive @skip( - # Skipped when true. - if: Boolean! - ) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT - - # Marks an element of a GraphQL schema as no longer supported. - directive @deprecated( - # Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/). - reason: String = "No longer supported" - ) on FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | ENUM_VALUE - - # Exposes a URL that specifies the behaviour of this scalar. - directive @specifiedBy( - # The URL that specifies the behaviour of this scalar. - url: String! - ) on SCALAR - - # A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations. - type __Schema { - description: String - - # A list of all types supported by this server. - types: [__Type!]! - - # The type that query operations will be rooted at. - queryType: __Type! - - # If this server supports mutation, the type that mutation operations will be rooted at. - mutationType: __Type - - # If this server support subscription, the type that subscription operations will be rooted at. - subscriptionType: __Type - - # A list of all directives supported by this server. - directives: [__Directive!]! - } - - # The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the \`__TypeKind\` enum. - # - # Depending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name, description and optional \`specifiedByUrl\`, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types. - type __Type { - kind: __TypeKind! - name: String - description: String - specifiedByUrl: String - fields(includeDeprecated: Boolean = false): [__Field!] - interfaces: [__Type!] - possibleTypes: [__Type!] - enumValues(includeDeprecated: Boolean = false): [__EnumValue!] - inputFields(includeDeprecated: Boolean = false): [__InputValue!] - ofType: __Type - } - - # An enum describing what kind of type a given \`__Type\` is. - enum __TypeKind { - # Indicates this type is a scalar. - SCALAR - - # Indicates this type is an object. \`fields\` and \`interfaces\` are valid fields. - OBJECT - - # Indicates this type is an interface. \`fields\`, \`interfaces\`, and \`possibleTypes\` are valid fields. - INTERFACE - - # Indicates this type is a union. \`possibleTypes\` is a valid field. - UNION - - # Indicates this type is an enum. \`enumValues\` is a valid field. - ENUM - - # Indicates this type is an input object. \`inputFields\` is a valid field. - INPUT_OBJECT - - # Indicates this type is a list. \`ofType\` is a valid field. - LIST - - # Indicates this type is a non-null. \`ofType\` is a valid field. - NON_NULL - } - - # Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type. - type __Field { - name: String! - description: String - args(includeDeprecated: Boolean = false): [__InputValue!]! - type: __Type! - isDeprecated: Boolean! - deprecationReason: String - } - - # Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value. - type __InputValue { - name: String! - description: String - type: __Type! - - # A GraphQL-formatted string representing the default value for this input value. - defaultValue: String - isDeprecated: Boolean! - deprecationReason: String - } - - # One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string. - type __EnumValue { - name: String! - description: String - isDeprecated: Boolean! - deprecationReason: String - } - - # A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document. - # - # In some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor. - type __Directive { - name: String! - description: String - isRepeatable: Boolean! - locations: [__DirectiveLocation!]! - args: [__InputValue!]! - } - - # A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies. - enum __DirectiveLocation { - # Location adjacent to a query operation. - QUERY - - # Location adjacent to a mutation operation. - MUTATION - - # Location adjacent to a subscription operation. - SUBSCRIPTION - - # Location adjacent to a field. - FIELD - - # Location adjacent to a fragment definition. - FRAGMENT_DEFINITION - - # Location adjacent to a fragment spread. - FRAGMENT_SPREAD - - # Location adjacent to an inline fragment. - INLINE_FRAGMENT - - # Location adjacent to a variable definition. - VARIABLE_DEFINITION - - # Location adjacent to a schema definition. - SCHEMA - - # Location adjacent to a scalar definition. - SCALAR - - # Location adjacent to an object type definition. - OBJECT - - # Location adjacent to a field definition. - FIELD_DEFINITION - - # Location adjacent to an argument definition. - ARGUMENT_DEFINITION - - # Location adjacent to an interface definition. - INTERFACE - - # Location adjacent to a union definition. - UNION - - # Location adjacent to an enum definition. - ENUM - - # Location adjacent to an enum value definition. - ENUM_VALUE - - # Location adjacent to an input object type definition. - INPUT_OBJECT - - # Location adjacent to an input object field definition. - INPUT_FIELD_DEFINITION - } - `); - }); }); diff --git a/src/utilities/buildASTSchema.d.ts b/src/utilities/buildASTSchema.d.ts index e0514369d8e..80592e03757 100644 --- a/src/utilities/buildASTSchema.d.ts +++ b/src/utilities/buildASTSchema.d.ts @@ -4,16 +4,6 @@ import { GraphQLSchema, GraphQLSchemaValidationOptions } from '../type/schema'; import { ParseOptions } from '../language/parser'; export interface BuildSchemaOptions extends GraphQLSchemaValidationOptions { - /** - * Descriptions are defined as preceding string literals, however an older - * experimental version of the SDL supported preceding comments as - * descriptions. Set to true to enable this deprecated behavior. - * This option is provided to ease adoption and will be removed in v16. - * - * Default: false - */ - commentDescriptions?: boolean; - /** * Set to true to assume the SDL is valid. * @@ -31,12 +21,6 @@ export interface BuildSchemaOptions extends GraphQLSchemaValidationOptions { * * Given that AST it constructs a GraphQLSchema. The resulting schema * has no resolve methods, so execution will use default resolvers. - * - * Accepts options as a second argument: - * - * - commentDescriptions: - * Provide true to use preceding comments as the description. - * */ export function buildASTSchema( documentAST: DocumentNode, diff --git a/src/utilities/buildASTSchema.js b/src/utilities/buildASTSchema.js index 067338611e9..d0c78340e85 100644 --- a/src/utilities/buildASTSchema.js +++ b/src/utilities/buildASTSchema.js @@ -17,16 +17,6 @@ import { extendSchemaImpl } from './extendSchema'; export type BuildSchemaOptions = {| ...GraphQLSchemaValidationOptions, - /** - * Descriptions are defined as preceding string literals, however an older - * experimental version of the SDL supported preceding comments as - * descriptions. Set to true to enable this deprecated behavior. - * This option is provided to ease adoption and will be removed in v16. - * - * Default: false - */ - commentDescriptions?: boolean, - /** * Set to true to assume the SDL is valid. * @@ -44,12 +34,6 @@ export type BuildSchemaOptions = {| * * Given that AST it constructs a GraphQLSchema. The resulting schema * has no resolve methods, so execution will use default resolvers. - * - * Accepts options as a second argument: - * - * - commentDescriptions: - * Provide true to use preceding comments as the description. - * */ export function buildASTSchema( documentAST: DocumentNode, @@ -121,7 +105,6 @@ export function buildSchema( }); return buildASTSchema(document, { - commentDescriptions: options?.commentDescriptions, assumeValidSDL: options?.assumeValidSDL, assumeValid: options?.assumeValid, }); diff --git a/src/utilities/extendSchema.d.ts b/src/utilities/extendSchema.d.ts index 6795e01437c..dedd60572c1 100644 --- a/src/utilities/extendSchema.d.ts +++ b/src/utilities/extendSchema.d.ts @@ -1,6 +1,4 @@ -import { Maybe } from '../jsutils/Maybe'; - -import { Location, DocumentNode, StringValueNode } from '../language/ast'; +import { DocumentNode } from '../language/ast'; import { GraphQLSchemaValidationOptions, GraphQLSchema, @@ -8,16 +6,6 @@ import { } from '../type/schema'; interface Options extends GraphQLSchemaValidationOptions { - /** - * Descriptions are defined as preceding string literals, however an older - * experimental version of the SDL supported preceding comments as - * descriptions. Set to true to enable this deprecated behavior. - * This option is provided to ease adoption and will be removed in v16. - * - * Default: false - */ - commentDescriptions?: boolean; - /** * Set to true to assume the SDL is valid. * @@ -37,12 +25,6 @@ interface Options extends GraphQLSchemaValidationOptions { * * This algorithm copies the provided schema, applying extensions while * producing the copy. The original schema remains unaltered. - * - * Accepts options as a third argument: - * - * - commentDescriptions: - * Provide true to use preceding comments as the description. - * */ export function extendSchema( schema: GraphQLSchema, @@ -58,18 +40,3 @@ export function extendSchemaImpl( documentAST: DocumentNode, options?: Options, ): GraphQLSchemaNormalizedConfig; - -/** - * Given an ast node, returns its string description. - * @deprecated: provided to ease adoption and will be removed in v16. - * - * Accepts options as a second argument: - * - * - commentDescriptions: - * Provide true to use preceding comments as the description. - * - */ -export function getDescription( - node: { readonly description?: StringValueNode; readonly loc?: Location }, - options?: Maybe<{ commentDescriptions?: boolean }>, -): string | undefined; diff --git a/src/utilities/extendSchema.js b/src/utilities/extendSchema.js index b7d3bfcfd0c..24e763a7452 100644 --- a/src/utilities/extendSchema.js +++ b/src/utilities/extendSchema.js @@ -8,9 +8,7 @@ import devAssert from '../jsutils/devAssert'; import type { DirectiveLocationEnum } from '../language/directiveLocation'; import type { - Location, DocumentNode, - StringValueNode, TypeNode, NamedTypeNode, SchemaDefinitionNode, @@ -34,8 +32,6 @@ import type { ScalarTypeExtensionNode, } from '../language/ast'; import { Kind } from '../language/kinds'; -import { TokenKind } from '../language/tokenKind'; -import { dedentBlockStringValue } from '../language/blockString'; import { isTypeDefinitionNode, isTypeExtensionNode, @@ -91,16 +87,6 @@ import { valueFromAST } from './valueFromAST'; type Options = {| ...GraphQLSchemaValidationOptions, - /** - * Descriptions are defined as preceding string literals, however an older - * experimental version of the SDL supported preceding comments as - * descriptions. Set to true to enable this deprecated behavior. - * This option is provided to ease adoption and will be removed in v16. - * - * Default: false - */ - commentDescriptions?: boolean, - /** * Set to true to assume the SDL is valid. * @@ -120,12 +106,6 @@ type Options = {| * * This algorithm copies the provided schema, applying extensions while * producing the copy. The original schema remains unaltered. - * - * Accepts options as a third argument: - * - * - commentDescriptions: - * Provide true to use preceding comments as the description. - * */ export function extendSchema( schema: GraphQLSchema, @@ -464,7 +444,7 @@ export function extendSchemaImpl( return new GraphQLDirective({ name: node.name.value, - description: getDescription(node, options), + description: node.description?.value, locations, isRepeatable: node.repeatable, args: buildArgumentMap(node.arguments), @@ -491,7 +471,7 @@ export function extendSchemaImpl( // value, that would throw immediately while type system validation // with validateSchema() will produce more actionable results. type: (getWrappedType(field.type): any), - description: getDescription(field, options), + description: field.description?.value, args: buildArgumentMap(field.arguments), deprecationReason: getDeprecationReason(field), astNode: field, @@ -516,7 +496,7 @@ export function extendSchemaImpl( argConfigMap[arg.name.value] = { type, - description: getDescription(arg, options), + description: arg.description?.value, defaultValue: valueFromAST(arg.defaultValue, type), deprecationReason: getDeprecationReason(arg), astNode: arg, @@ -543,7 +523,7 @@ export function extendSchemaImpl( inputFieldMap[field.name.value] = { type, - description: getDescription(field, options), + description: field.description?.value, defaultValue: valueFromAST(field.defaultValue, type), deprecationReason: getDeprecationReason(field), astNode: field, @@ -563,7 +543,7 @@ export function extendSchemaImpl( for (const value of valuesNodes) { enumValueMap[value.name.value] = { - description: getDescription(value, options), + description: value.description?.value, deprecationReason: getDeprecationReason(value), astNode: value, }; @@ -617,7 +597,6 @@ export function extendSchemaImpl( function buildType(astNode: TypeDefinitionNode): GraphQLNamedType { const name = astNode.name.value; - const description = getDescription(astNode, options); const extensionNodes = typeExtensionsMap[name] ?? []; switch (astNode.kind) { @@ -627,7 +606,7 @@ export function extendSchemaImpl( return new GraphQLObjectType({ name, - description, + description: astNode.description?.value, interfaces: () => buildInterfaces(allNodes), fields: () => buildFieldMap(allNodes), astNode, @@ -640,7 +619,7 @@ export function extendSchemaImpl( return new GraphQLInterfaceType({ name, - description, + description: astNode.description?.value, interfaces: () => buildInterfaces(allNodes), fields: () => buildFieldMap(allNodes), astNode, @@ -653,7 +632,7 @@ export function extendSchemaImpl( return new GraphQLEnumType({ name, - description, + description: astNode.description?.value, values: buildEnumValueMap(allNodes), astNode, extensionASTNodes, @@ -665,7 +644,7 @@ export function extendSchemaImpl( return new GraphQLUnionType({ name, - description, + description: astNode.description?.value, types: () => buildUnionTypes(allNodes), astNode, extensionASTNodes, @@ -676,7 +655,7 @@ export function extendSchemaImpl( return new GraphQLScalarType({ name, - description, + description: astNode.description?.value, specifiedByUrl: getSpecifiedByUrl(astNode), astNode, extensionASTNodes, @@ -688,7 +667,7 @@ export function extendSchemaImpl( return new GraphQLInputObjectType({ name, - description, + description: astNode.description?.value, fields: () => buildInputFieldMap(allNodes), astNode, extensionASTNodes, @@ -732,50 +711,3 @@ function getSpecifiedByUrl( const specifiedBy = getDirectiveValues(GraphQLSpecifiedByDirective, node); return (specifiedBy?.url: any); } - -/** - * Given an ast node, returns its string description. - * @deprecated: provided to ease adoption and will be removed in v16. - * - * Accepts options as a second argument: - * - * - commentDescriptions: - * Provide true to use preceding comments as the description. - * - */ -export function getDescription( - node: { +description?: StringValueNode, +loc?: Location, ... }, - options: ?{ commentDescriptions?: boolean, ... }, -): void | string { - if (node.description) { - return node.description.value; - } - if (options?.commentDescriptions === true) { - const rawValue = getLeadingCommentBlock(node); - if (rawValue !== undefined) { - return dedentBlockStringValue('\n' + rawValue); - } - } -} - -function getLeadingCommentBlock(node): void | string { - const loc = node.loc; - if (!loc) { - return; - } - const comments = []; - let token = loc.startToken.prev; - while ( - token != null && - token.kind === TokenKind.COMMENT && - token.next && - token.prev && - token.line + 1 === token.next.line && - token.line !== token.prev.line - ) { - const value = String(token.value); - comments.push(value); - token = token.prev; - } - return comments.length > 0 ? comments.reverse().join('\n') : undefined; -} diff --git a/src/utilities/index.d.ts b/src/utilities/index.d.ts index 5f2caa84fb9..a690e640e95 100644 --- a/src/utilities/index.d.ts +++ b/src/utilities/index.d.ts @@ -46,12 +46,7 @@ export { } from './buildASTSchema'; // Extends an existing GraphQLSchema from a parsed GraphQL Schema language AST. -export { - extendSchema, - // @deprecated: Get the description from a schema AST node and supports legacy - // syntax for specifying descriptions - will be removed in v16 - getDescription, -} from './extendSchema'; +export { extendSchema } from './extendSchema'; // Sort a GraphQLSchema. export { lexicographicSortSchema } from './lexicographicSortSchema'; diff --git a/src/utilities/index.js b/src/utilities/index.js index 15b84fa0df4..b4c8372f04e 100644 --- a/src/utilities/index.js +++ b/src/utilities/index.js @@ -44,12 +44,7 @@ export { buildASTSchema, buildSchema } from './buildASTSchema'; export type { BuildSchemaOptions } from './buildASTSchema'; // Extends an existing GraphQLSchema from a parsed GraphQL Schema language AST. -export { - extendSchema, - // @deprecated: Get the description from a schema AST node and supports legacy - // syntax for specifying descriptions - will be removed in v16. - getDescription, -} from './extendSchema'; +export { extendSchema } from './extendSchema'; // Sort a GraphQLSchema. export { lexicographicSortSchema } from './lexicographicSortSchema'; diff --git a/src/utilities/printSchema.d.ts b/src/utilities/printSchema.d.ts index 1417ee5892b..57232961c2c 100644 --- a/src/utilities/printSchema.d.ts +++ b/src/utilities/printSchema.d.ts @@ -1,30 +1,8 @@ import { GraphQLSchema } from '../type/schema'; import { GraphQLNamedType } from '../type/definition'; -export interface Options { - /** - * Descriptions are defined as preceding string literals, however an older - * experimental version of the SDL supported preceding comments as - * descriptions. Set to true to enable this deprecated behavior. - * This option is provided to ease adoption and will be removed in v16. - * - * Default: false - */ - commentDescriptions?: boolean; -} +export function printSchema(schema: GraphQLSchema): string; -/** - * Accepts options as a second argument: - * - * - commentDescriptions: - * Provide true to use preceding comments as the description. - * - */ -export function printSchema(schema: GraphQLSchema, options?: Options): string; +export function printIntrospectionSchema(schema: GraphQLSchema): string; -export function printIntrospectionSchema( - schema: GraphQLSchema, - options?: Options, -): string; - -export function printType(type: GraphQLNamedType, options?: Options): string; +export function printType(type: GraphQLNamedType): string; diff --git a/src/utilities/printSchema.js b/src/utilities/printSchema.js index c76f01bef8c..2d02ef6fd1e 100644 --- a/src/utilities/printSchema.js +++ b/src/utilities/printSchema.js @@ -36,44 +36,16 @@ import { import { astFromValue } from './astFromValue'; -type Options = {| - /** - * Descriptions are defined as preceding string literals, however an older - * experimental version of the SDL supported preceding comments as - * descriptions. Set to true to enable this deprecated behavior. - * This option is provided to ease adoption and will be removed in v16. - * - * Default: false - */ - commentDescriptions?: boolean, -|}; - -/** - * Accepts options as a second argument: - * - * - commentDescriptions: - * Provide true to use preceding comments as the description. - * - */ -export function printSchema(schema: GraphQLSchema, options?: Options): string { +export function printSchema(schema: GraphQLSchema): string { return printFilteredSchema( schema, (n) => !isSpecifiedDirective(n), isDefinedType, - options, ); } -export function printIntrospectionSchema( - schema: GraphQLSchema, - options?: Options, -): string { - return printFilteredSchema( - schema, - isSpecifiedDirective, - isIntrospectionType, - options, - ); +export function printIntrospectionSchema(schema: GraphQLSchema): string { + return printFilteredSchema(schema, isSpecifiedDirective, isIntrospectionType); } function isDefinedType(type: GraphQLNamedType): boolean { @@ -84,7 +56,6 @@ function printFilteredSchema( schema: GraphQLSchema, directiveFilter: (type: GraphQLDirective) => boolean, typeFilter: (type: GraphQLNamedType) => boolean, - options, ): string { const directives = schema.getDirectives().filter(directiveFilter); const types = objectValues(schema.getTypeMap()).filter(typeFilter); @@ -92,8 +63,8 @@ function printFilteredSchema( return ( [printSchemaDefinition(schema)] .concat( - directives.map((directive) => printDirective(directive, options)), - types.map((type) => printType(type, options)), + directives.map((directive) => printDirective(directive)), + types.map((type) => printType(type)), ) .filter(Boolean) .join('\n\n') + '\n' @@ -122,9 +93,7 @@ function printSchemaDefinition(schema: GraphQLSchema): ?string { operationTypes.push(` subscription: ${subscriptionType.name}`); } - return ( - printDescription({}, schema) + `schema {\n${operationTypes.join('\n')}\n}` - ); + return printDescription(schema) + `schema {\n${operationTypes.join('\n')}\n}`; } /** @@ -158,36 +127,34 @@ function isSchemaOfCommonNames(schema: GraphQLSchema): boolean { return true; } -export function printType(type: GraphQLNamedType, options?: Options): string { +export function printType(type: GraphQLNamedType): string { if (isScalarType(type)) { - return printScalar(type, options); + return printScalar(type); } if (isObjectType(type)) { - return printObject(type, options); + return printObject(type); } if (isInterfaceType(type)) { - return printInterface(type, options); + return printInterface(type); } if (isUnionType(type)) { - return printUnion(type, options); + return printUnion(type); } if (isEnumType(type)) { - return printEnum(type, options); + return printEnum(type); } // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2618') if (isInputObjectType(type)) { - return printInputObject(type, options); + return printInputObject(type); } // istanbul ignore next (Not reachable. All possible types have been considered) invariant(false, 'Unexpected type: ' + inspect((type: empty))); } -function printScalar(type: GraphQLScalarType, options): string { +function printScalar(type: GraphQLScalarType): string { return ( - printDescription(options, type) + - `scalar ${type.name}` + - printSpecifiedByUrl(type) + printDescription(type) + `scalar ${type.name}` + printSpecifiedByUrl(type) ); } @@ -200,66 +167,58 @@ function printImplementedInterfaces( : ''; } -function printObject(type: GraphQLObjectType, options): string { +function printObject(type: GraphQLObjectType): string { return ( - printDescription(options, type) + + printDescription(type) + `type ${type.name}` + printImplementedInterfaces(type) + - printFields(options, type) + printFields(type) ); } -function printInterface(type: GraphQLInterfaceType, options): string { +function printInterface(type: GraphQLInterfaceType): string { return ( - printDescription(options, type) + + printDescription(type) + `interface ${type.name}` + printImplementedInterfaces(type) + - printFields(options, type) + printFields(type) ); } -function printUnion(type: GraphQLUnionType, options): string { +function printUnion(type: GraphQLUnionType): string { const types = type.getTypes(); const possibleTypes = types.length ? ' = ' + types.join(' | ') : ''; - return printDescription(options, type) + 'union ' + type.name + possibleTypes; + return printDescription(type) + 'union ' + type.name + possibleTypes; } -function printEnum(type: GraphQLEnumType, options): string { +function printEnum(type: GraphQLEnumType): string { const values = type .getValues() .map( (value, i) => - printDescription(options, value, ' ', !i) + + printDescription(value, ' ', !i) + ' ' + value.name + printDeprecated(value.deprecationReason), ); - return ( - printDescription(options, type) + `enum ${type.name}` + printBlock(values) - ); + return printDescription(type) + `enum ${type.name}` + printBlock(values); } -function printInputObject(type: GraphQLInputObjectType, options): string { +function printInputObject(type: GraphQLInputObjectType): string { const fields = objectValues(type.getFields()).map( - (f, i) => - printDescription(options, f, ' ', !i) + ' ' + printInputValue(f), - ); - return ( - printDescription(options, type) + `input ${type.name}` + printBlock(fields) + (f, i) => printDescription(f, ' ', !i) + ' ' + printInputValue(f), ); + return printDescription(type) + `input ${type.name}` + printBlock(fields); } -function printFields( - options, - type: GraphQLObjectType | GraphQLInterfaceType, -): string { +function printFields(type: GraphQLObjectType | GraphQLInterfaceType): string { const fields = objectValues(type.getFields()).map( (f, i) => - printDescription(options, f, ' ', !i) + + printDescription(f, ' ', !i) + ' ' + f.name + - printArgs(options, f.args, ' ') + + printArgs(f.args, ' ') + ': ' + String(f.type) + printDeprecated(f.deprecationReason), @@ -272,7 +231,6 @@ function printBlock(items: $ReadOnlyArray): string { } function printArgs( - options, args: Array, indentation: string = '', ): string { @@ -290,7 +248,7 @@ function printArgs( args .map( (arg, i) => - printDescription(options, arg, ' ' + indentation, !i) + + printDescription(arg, ' ' + indentation, !i) + ' ' + indentation + printInputValue(arg), @@ -311,12 +269,12 @@ function printInputValue(arg: GraphQLInputField): string { return argDecl + printDeprecated(arg.deprecationReason); } -function printDirective(directive: GraphQLDirective, options): string { +function printDirective(directive: GraphQLDirective): string { return ( - printDescription(options, directive) + + printDescription(directive) + 'directive @' + directive.name + - printArgs(options, directive.args) + + printArgs(directive.args) + (directive.isRepeatable ? ' repeatable' : '') + ' on ' + directive.locations.join(' | ') @@ -348,7 +306,6 @@ function printSpecifiedByUrl(scalar: GraphQLScalarType): string { } function printDescription( - options, def: { +description: ?string, ... }, indentation: string = '', firstInBlock: boolean = true, @@ -358,10 +315,6 @@ function printDescription( return ''; } - if (options?.commentDescriptions === true) { - return printDescriptionWithComments(description, indentation, firstInBlock); - } - const preferMultipleLines = description.length > 70; const blockString = printBlockString(description, '', preferMultipleLines); const prefix = @@ -369,13 +322,3 @@ function printDescription( return prefix + blockString.replace(/\n/g, '\n' + indentation) + '\n'; } - -function printDescriptionWithComments(description, indentation, firstInBlock) { - const prefix = indentation && !firstInBlock ? '\n' : ''; - const comment = description - .split('\n') - .map((line) => indentation + (line !== '' ? '# ' + line : '#')) - .join('\n'); - - return prefix + comment + '\n'; -}