Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support @defer directive #255

Merged
merged 1 commit into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions validator/prelude.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ directive @deprecated(reason: String = "No longer supported") on FIELD_DEFINITIO
"The @specifiedBy built-in directive is used within the type system definition language to provide a scalar specification URL for specifying the behavior of custom scalar types."
directive @specifiedBy(url: String!) on SCALAR

"The @defer directive may be specified on a fragment spread to imply de-prioritization, that causes the fragment to be omitted in the initial response, and delivered as a subsequent response afterward. A query with @defer directive will cause the request to potentially return multiple responses, where non-deferred data is delivered in the initial response and data deferred delivered in a subsequent response. @include and @skip take precedence over @defer."
directive @defer(if: Boolean = true, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT

type __Schema {
description: String
types: [__Type!]!
Expand Down
2 changes: 1 addition & 1 deletion validator/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func ValidateSchemaDocument(ast *SchemaDocument) (*Schema, error) {
// scalars, it may (§3.13) define builtin directives. Here we check for
// that, and reject doubly-defined directives otherwise.
switch dir.Name {
case "include", "skip", "deprecated", "specifiedBy": // the builtins
case "include", "skip", "deprecated", "specifiedBy", "defer": // the builtins
// In principle here we might want to validate that the
// directives are the same. But they might not be, if the
// server has an older spec than we do. (Plus, validating this
Expand Down
5 changes: 5 additions & 0 deletions validator/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func TestLoadSchema(t *testing.T) {
require.Equal(t, "Boolean", boolDef.Name)
require.Equal(t, ast.Scalar, boolDef.Kind)
require.Equal(t, "The `Boolean` scalar type represents `true` or `false`.", boolDef.Description)

deferDef := s.Directives["defer"]
require.Equal(t, "defer", deferDef.Name, "@defer exists.")
require.Equal(t, "if", deferDef.Arguments[0].Name, "@defer has \"if\" argument.")
require.Equal(t, "label", deferDef.Arguments[1].Name, "@defer has \"label\" argument.")
})
t.Run("swapi", func(t *testing.T) {
file, err := os.ReadFile("testdata/swapi.graphql")
Expand Down