Skip to content

Commit 45ac961

Browse files
add defer directive type
1 parent 576682f commit 45ac961

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
@@ -590,6 +590,14 @@ describe('Type System Printer', () => {
590590
if: Boolean!
591591
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
592592
593+
"""
594+
Directs the executor to defer this fragment when the \`if\` argument is true or undefined.
595+
"""
596+
directive @defer(
597+
"""Defer fragment when true or undefined."""
598+
if: Boolean
599+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
600+
593601
"""Marks an element of a GraphQL schema as no longer supported."""
594602
directive @deprecated(
595603
"""
@@ -803,6 +811,12 @@ describe('Type System Printer', () => {
803811
if: Boolean!
804812
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
805813
814+
# Directs the executor to defer this fragment when the \`if\` argument is true or undefined.
815+
directive @defer(
816+
# Defer fragment when true or undefined.
817+
if: Boolean
818+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
819+
806820
# Marks an element of a GraphQL schema as no longer supported.
807821
directive @deprecated(
808822
# 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)