Skip to content

Commit 61bf1b5

Browse files
add defer directive type
1 parent d680d07 commit 61bf1b5

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

src/type/__tests__/introspection-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,21 @@ describe('Introspection', () => {
865865
},
866866
],
867867
},
868+
{
869+
name: 'defer',
870+
locations: ['FRAGMENT_SPREAD', 'INLINE_FRAGMENT'],
871+
args: [
872+
{
873+
defaultValue: null,
874+
name: 'if',
875+
type: {
876+
kind: 'SCALAR',
877+
name: 'Boolean',
878+
ofType: null,
879+
},
880+
},
881+
],
882+
},
868883
{
869884
name: 'deprecated',
870885
isRepeatable: false,

src/type/directives.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,25 @@ export const GraphQLSkipDirective = new GraphQLDirective({
170170
},
171171
});
172172

173+
/**
174+
* Used to conditionally defer fragments.
175+
*/
176+
export const GraphQLDeferDirective = new GraphQLDirective({
177+
name: 'defer',
178+
description:
179+
'Directs the executor to defer this fragment when the `if` argument is true or undefined.',
180+
locations: [
181+
DirectiveLocation.FRAGMENT_SPREAD,
182+
DirectiveLocation.INLINE_FRAGMENT,
183+
],
184+
args: {
185+
if: {
186+
type: GraphQLBoolean,
187+
description: 'Defer fragment when true or undefined.',
188+
},
189+
},
190+
});
191+
173192
/**
174193
* Constant string used for default reason for a deprecation.
175194
*/
@@ -198,6 +217,7 @@ export const GraphQLDeprecatedDirective = new GraphQLDirective({
198217
export const specifiedDirectives = Object.freeze([
199218
GraphQLIncludeDirective,
200219
GraphQLSkipDirective,
220+
GraphQLDeferDirective,
201221
GraphQLDeprecatedDirective,
202222
]);
203223

src/utilities/__tests__/findBreakingChanges-test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { describe, it } from 'mocha';
66
import { GraphQLSchema } from '../../type/schema';
77
import {
88
GraphQLSkipDirective,
9+
GraphQLDeferDirective,
910
GraphQLIncludeDirective,
1011
GraphQLDeprecatedDirective,
1112
} from '../../type/directives';
@@ -799,7 +800,11 @@ describe('findBreakingChanges', () => {
799800
const oldSchema = new GraphQLSchema({});
800801

801802
const newSchema = new GraphQLSchema({
802-
directives: [GraphQLSkipDirective, GraphQLIncludeDirective],
803+
directives: [
804+
GraphQLSkipDirective,
805+
GraphQLIncludeDirective,
806+
GraphQLDeferDirective,
807+
],
803808
});
804809

805810
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([

src/utilities/__tests__/schemaPrinter-test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,14 @@ describe('Type System Printer', () => {
614614
if: Boolean!
615615
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
616616
617+
"""
618+
Directs the executor to defer this fragment when the \`if\` argument is true or undefined.
619+
"""
620+
directive @defer(
621+
"""Defer fragment when true or undefined."""
622+
if: Boolean
623+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
624+
617625
"""Marks an element of a GraphQL schema as no longer supported."""
618626
directive @deprecated(
619627
"""
@@ -921,6 +929,17 @@ describe('Type System Printer', () => {
921929
isDeprecated: Boolean!
922930
deprecationReason: String
923931
}
932+
# Directs the executor to defer this fragment when the \`if\` argument is true or undefined.
933+
directive @defer(
934+
# Defer fragment when true or undefined.
935+
if: Boolean
936+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
937+
938+
# Marks an element of a GraphQL schema as no longer supported.
939+
directive @deprecated(
940+
# 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/).
941+
reason: String = "No longer supported"
942+
) on FIELD_DEFINITION | ENUM_VALUE
924943
925944
# A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
926945
#

0 commit comments

Comments
 (0)