Skip to content

Commit

Permalink
Drop support for long deprecated comments as descriptions (#2900)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jan 31, 2021
1 parent 5d9b5bb commit ec2352a
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 593 deletions.
3 changes: 0 additions & 3 deletions src/index.d.ts
Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions src/index.js
Expand Up @@ -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,
Expand Down
34 changes: 2 additions & 32 deletions src/utilities/__tests__/buildASTSchema-test.js
Expand Up @@ -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 {
Expand Down Expand Up @@ -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');

Expand Down
82 changes: 0 additions & 82 deletions src/utilities/__tests__/extendSchema-test.js
Expand Up @@ -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');

Expand Down Expand Up @@ -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');
Expand Down
197 changes: 0 additions & 197 deletions src/utilities/__tests__/printSchema-test.js
Expand Up @@ -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
}
`);
});
});
16 changes: 0 additions & 16 deletions src/utilities/buildASTSchema.d.ts
Expand Up @@ -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.
*
Expand All @@ -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,
Expand Down

0 comments on commit ec2352a

Please sign in to comment.