Skip to content

Commit e5ce12e

Browse files
lilianammmatosrobrichard
authored andcommitted
add defer directive type
1 parent a6c50de commit e5ce12e

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

src/type/__tests__/introspection-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,21 @@ describe('Introspection', () => {
845845
},
846846
],
847847
},
848+
{
849+
name: 'defer',
850+
locations: ['FRAGMENT_SPREAD', 'INLINE_FRAGMENT'],
851+
args: [
852+
{
853+
defaultValue: null,
854+
name: 'if',
855+
type: {
856+
kind: 'SCALAR',
857+
name: 'Boolean',
858+
ofType: null,
859+
},
860+
},
861+
],
862+
},
848863
{
849864
name: 'deprecated',
850865
locations: ['FIELD_DEFINITION', 'ENUM_VALUE'],

src/type/directives.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,25 @@ export const GraphQLSkipDirective = new GraphQLDirective({
167167
},
168168
});
169169

170+
/**
171+
* Used to conditionally defer fragments.
172+
*/
173+
export const GraphQLDeferDirective = new GraphQLDirective({
174+
name: 'defer',
175+
description:
176+
'Directs the executor to defer this fragment when the `if` argument is true or undefined.',
177+
locations: [
178+
DirectiveLocation.FRAGMENT_SPREAD,
179+
DirectiveLocation.INLINE_FRAGMENT,
180+
],
181+
args: {
182+
if: {
183+
type: GraphQLBoolean,
184+
description: 'Defer fragment when true or undefined.',
185+
},
186+
},
187+
});
188+
170189
/**
171190
* Constant string used for default reason for a deprecation.
172191
*/
@@ -195,6 +214,7 @@ export const GraphQLDeprecatedDirective = new GraphQLDirective({
195214
export const specifiedDirectives = Object.freeze([
196215
GraphQLIncludeDirective,
197216
GraphQLSkipDirective,
217+
GraphQLDeferDirective,
198218
GraphQLDeprecatedDirective,
199219
]);
200220

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';
@@ -790,7 +791,11 @@ describe('findBreakingChanges', () => {
790791
const oldSchema = new GraphQLSchema({});
791792

792793
const newSchema = new GraphQLSchema({
793-
directives: [GraphQLSkipDirective, GraphQLIncludeDirective],
794+
directives: [
795+
GraphQLSkipDirective,
796+
GraphQLIncludeDirective,
797+
GraphQLDeferDirective,
798+
],
794799
});
795800

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

src/utilities/__tests__/schemaPrinter-test.js

Lines changed: 14 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
"""
@@ -827,6 +835,12 @@ describe('Type System Printer', () => {
827835
if: Boolean!
828836
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
829837
838+
# Directs the executor to defer this fragment when the \`if\` argument is true or undefined.
839+
directive @defer(
840+
# Defer fragment when true or undefined.
841+
if: Boolean
842+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
843+
830844
# Marks an element of a GraphQL schema as no longer supported.
831845
directive @deprecated(
832846
# 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/).

0 commit comments

Comments
 (0)