Skip to content

Commit

Permalink
Allow deprecating input fields and arguments (#2733)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored Sep 3, 2020
1 parent 1012738 commit 01bcc7d
Show file tree
Hide file tree
Showing 16 changed files with 664 additions and 46 deletions.
3 changes: 3 additions & 0 deletions src/type/__tests__/definition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ describe('Type System: Objects', () => {
description: undefined,
type: ScalarType,
defaultValue: undefined,
deprecationReason: undefined,
extensions: undefined,
astNode: undefined,
},
Expand Down Expand Up @@ -771,6 +772,7 @@ describe('Type System: Input Objects', () => {
description: undefined,
type: ScalarType,
defaultValue: undefined,
deprecationReason: undefined,
extensions: undefined,
astNode: undefined,
},
Expand All @@ -791,6 +793,7 @@ describe('Type System: Input Objects', () => {
type: ScalarType,
defaultValue: undefined,
extensions: undefined,
deprecationReason: undefined,
astNode: undefined,
},
});
Expand Down
2 changes: 2 additions & 0 deletions src/type/__tests__/directive-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('Type System: Directive', () => {
description: undefined,
type: GraphQLString,
defaultValue: undefined,
deprecationReason: undefined,
extensions: undefined,
astNode: undefined,
},
Expand All @@ -45,6 +46,7 @@ describe('Type System: Directive', () => {
description: undefined,
type: GraphQLInt,
defaultValue: undefined,
deprecationReason: undefined,
extensions: undefined,
astNode: undefined,
},
Expand Down
243 changes: 240 additions & 3 deletions src/type/__tests__/introspection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,17 @@ describe('Introspection', () => {
},
{
name: 'inputFields',
args: [],
args: [
{
name: 'includeDeprecated',
type: {
kind: 'SCALAR',
name: 'Boolean',
ofType: null,
},
defaultValue: 'false',
},
],
type: {
kind: 'LIST',
name: null,
Expand Down Expand Up @@ -450,7 +460,17 @@ describe('Introspection', () => {
},
{
name: 'args',
args: [],
args: [
{
name: 'includeDeprecated',
type: {
kind: 'SCALAR',
name: 'Boolean',
ofType: null,
},
defaultValue: 'false',
},
],
type: {
kind: 'NON_NULL',
name: null,
Expand Down Expand Up @@ -575,6 +595,32 @@ describe('Introspection', () => {
isDeprecated: false,
deprecationReason: null,
},
{
name: 'isDeprecated',
args: [],
type: {
kind: 'NON_NULL',
name: null,
ofType: {
kind: 'SCALAR',
name: 'Boolean',
ofType: null,
},
},
isDeprecated: false,
deprecationReason: null,
},
{
name: 'deprecationReason',
args: [],
type: {
kind: 'SCALAR',
name: 'String',
ofType: null,
},
isDeprecated: false,
deprecationReason: null,
},
],
inputFields: null,
interfaces: [],
Expand Down Expand Up @@ -893,7 +939,12 @@ describe('Introspection', () => {
{
name: 'deprecated',
isRepeatable: false,
locations: ['FIELD_DEFINITION', 'ENUM_VALUE'],
locations: [
'FIELD_DEFINITION',
'ARGUMENT_DEFINITION',
'INPUT_FIELD_DEFINITION',
'ENUM_VALUE',
],
args: [
{
defaultValue: '"No longer supported"',
Expand Down Expand Up @@ -1122,6 +1173,103 @@ describe('Introspection', () => {
});
});

it('identifies deprecated args', () => {
const schema = buildSchema(`
type Query {
someField(
nonDeprecated: String
deprecated: String @deprecated(reason: "Removed in 1.0")
deprecatedWithEmptyReason: String @deprecated(reason: "")
): String
}
`);

const source = `
{
__type(name: "Query") {
fields {
args(includeDeprecated: true) {
name
isDeprecated,
deprecationReason
}
}
}
}
`;

expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
__type: {
fields: [
{
args: [
{
name: 'nonDeprecated',
isDeprecated: false,
deprecationReason: null,
},
{
name: 'deprecated',
isDeprecated: true,
deprecationReason: 'Removed in 1.0',
},
{
name: 'deprecatedWithEmptyReason',
isDeprecated: true,
deprecationReason: '',
},
],
},
],
},
},
});
});

it('respects the includeDeprecated parameter for args', () => {
const schema = buildSchema(`
type Query {
someField(
nonDeprecated: String
deprecated: String @deprecated(reason: "Removed in 1.0")
): String
}
`);

const source = `
{
__type(name: "Query") {
fields {
trueArgs: args(includeDeprecated: true) {
name
}
falseArgs: args(includeDeprecated: false) {
name
}
omittedArgs: args {
name
}
}
}
}
`;

expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
__type: {
fields: [
{
trueArgs: [{ name: 'nonDeprecated' }, { name: 'deprecated' }],
falseArgs: [{ name: 'nonDeprecated' }],
omittedArgs: [{ name: 'nonDeprecated' }],
},
],
},
},
});
});

it('identifies deprecated enum values', () => {
const schema = buildSchema(`
enum SomeEnum {
Expand Down Expand Up @@ -1224,6 +1372,95 @@ describe('Introspection', () => {
});
});

it('identifies deprecated for input fields', () => {
const schema = buildSchema(`
input SomeInputObject {
nonDeprecated: String
deprecated: String @deprecated(reason: "Removed in 1.0")
deprecatedWithEmptyReason: String @deprecated(reason: "")
}
type Query {
someField(someArg: SomeInputObject): String
}
`);

const source = `
{
__type(name: "SomeInputObject") {
inputFields(includeDeprecated: true) {
name
isDeprecated,
deprecationReason
}
}
}
`;

expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
__type: {
inputFields: [
{
name: 'nonDeprecated',
isDeprecated: false,
deprecationReason: null,
},
{
name: 'deprecated',
isDeprecated: true,
deprecationReason: 'Removed in 1.0',
},
{
name: 'deprecatedWithEmptyReason',
isDeprecated: true,
deprecationReason: '',
},
],
},
},
});
});

it('respects the includeDeprecated parameter for input fields', () => {
const schema = buildSchema(`
input SomeInputObject {
nonDeprecated: String
deprecated: String @deprecated(reason: "Removed in 1.0")
}
type Query {
someField(someArg: SomeInputObject): String
}
`);

const source = `
{
__type(name: "SomeInputObject") {
trueFields: inputFields(includeDeprecated: true) {
name
}
falseFields: inputFields(includeDeprecated: false) {
name
}
omittedFields: inputFields {
name
}
}
}
`;

expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
__type: {
trueFields: [{ name: 'nonDeprecated' }, { name: 'deprecated' }],
falseFields: [{ name: 'nonDeprecated' }],
omittedFields: [{ name: 'nonDeprecated' }],
},
},
});
});

it('fails as expected on the __type root field without an arg', () => {
const schema = buildSchema(`
type Query {
Expand Down
2 changes: 2 additions & 0 deletions src/type/__tests__/predicate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ describe('Type predicates', () => {
name: 'someArg',
description: undefined,
defaultValue: undefined,
deprecationReason: null,
extensions: undefined,
astNode: undefined,
...config,
Expand Down Expand Up @@ -608,6 +609,7 @@ describe('Type predicates', () => {
name: 'someInputField',
description: undefined,
defaultValue: undefined,
deprecationReason: null,
extensions: undefined,
astNode: undefined,
...config,
Expand Down
Loading

0 comments on commit 01bcc7d

Please sign in to comment.