Skip to content
This repository has been archived by the owner on Mar 2, 2022. It is now read-only.

supported repeatable #2

Merged
merged 1 commit into from
Apr 3, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions ast/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ type EnumValueDefinition struct {
}

type DirectiveDefinition struct {
Description string
Name string
Arguments ArgumentDefinitionList
Locations []DirectiveLocation
Position *Position `dump:"-"`
Description string
Name string
Arguments ArgumentDefinitionList
Locations []DirectiveLocation
IsRepeatable bool
Position *Position `dump:"-"`
}
5 changes: 5 additions & 0 deletions parser/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,11 @@ func (p *parser) parseDirectiveDefinition(description string) *DirectiveDefiniti
def.Name = p.parseName()
def.Arguments = p.parseArgumentDefs()

if peek := p.peek(); peek.Kind == lexer.Name && peek.Value == "repeatable" {
def.IsRepeatable = true
p.skip(lexer.Name)
}

p.expectKeyword("on")
def.Locations = p.parseDirectiveLocations()
return &def
Expand Down
12 changes: 12 additions & 0 deletions parser/schema_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,18 @@ directives:
Name: "foo"
Locations: [DirectiveLocation]
- DirectiveLocation("FIELD")
IsRepeatable: false

- name: repeatable
input: directive @foo repeatable on FIELD
ast: |
<SchemaDocument>
Directives: [DirectiveDefinition]
- <DirectiveDefinition>
Name: "foo"
Locations: [DirectiveLocation]
- DirectiveLocation("FIELD")
IsRepeatable: true

- name: invalid location
input: "directive @foo on FIELD | INCORRECT_LOCATION"
Expand Down
1 change: 1 addition & 0 deletions validator/prelude.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type __Directive {
description: String
locations: [__DirectiveLocation!]!
args: [__InputValue!]!
isRepeatable: Boolean!
}

enum __DirectiveLocation {
Expand Down
11 changes: 11 additions & 0 deletions validator/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ func TestLoadSchema(t *testing.T) {
require.Equal(t, "dogEvents", s.Subscription.Fields[0].Name)

require.Equal(t, "owner", s.Types["Dog"].Fields[1].Name)

directives := s.Types["Person"].Directives
require.Len(t, directives, 2)
wantArgs := []string{"sushi", "tempura"}
for i, directive := range directives {
require.Equal(t, "favorite", directive.Name)
require.True(t, directive.Definition.IsRepeatable)
for _, arg := range directive.Arguments {
require.Equal(t, wantArgs[i], arg.Value.Raw)
}
}
})

testrunner.Test(t, "./schema_test.yml", func(t *testing.T, input string) testrunner.Spec {
Expand Down
4 changes: 3 additions & 1 deletion validator/testdata/extensions.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ type Dog {
name: String!
}

type Person {
type Person @favorite(name: "sushi") @favorite(name: "tempura") {
name: String!
}

directive @favorite(name: String!) repeatable on OBJECT

extend type Dog {
owner: Person! @permission(permission: "admin")
}
Expand Down