Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Commit 42b06d4

Browse files
authored
Merge pull request #19 from Code-Hex/feature/update-wrapper
supported isRepeatable schema
2 parents d165e92 + c3e9127 commit 42b06d4

File tree

4 files changed

+74
-9
lines changed

4 files changed

+74
-9
lines changed

internal/gqlgen/gqlgen.go

+2
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS
420420
if out.Values[i] == gql.Null {
421421
invalids++
422422
}
423+
case "isRepeatable":
424+
out.Values[i] = gql.MarshalBoolean(obj.IsRepeatable)
423425
default:
424426
panic("unknown field " + strconv.Quote(field.Name))
425427
}

internal/gqlgen/gqlgen_test.yml

+59-1
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,62 @@ tests:
245245
}
246246
}
247247
json: |
248-
{"__schema":{"description":"This is a simple schema"}}
248+
{"__schema":{"description":"This is a simple schema"}}
249+
250+
- name: querying schema operation types
251+
schema: |
252+
schema {
253+
query: Query
254+
mutation: Mutation
255+
subscription: Subscription
256+
}
257+
type Query {
258+
queryField: String
259+
}
260+
type Mutation {
261+
mutationField: String
262+
}
263+
type Subscription {
264+
subscriptionField: String
265+
}
266+
query: |
267+
{
268+
__schema {
269+
queryType { name }
270+
mutationType { name }
271+
subscriptionType { name }
272+
}
273+
}
274+
json: |
275+
{"__schema":{"mutationType":{"name":"Mutation"},"queryType":{"name":"Query"},"subscriptionType":{"name":"Subscription"}}}
276+
277+
- name: querying schema operation types
278+
schema: |
279+
directive @foo repeatable on FIELD_DEFINITION
280+
281+
schema {
282+
query: Query
283+
}
284+
type Query {
285+
queryField: String @foo @foo
286+
}
287+
query: |
288+
{
289+
__schema {
290+
queryType { name }
291+
directives {
292+
name
293+
isRepeatable
294+
}
295+
}
296+
}
297+
json: |
298+
{"__schema":
299+
{"queryType":{"name":"Query"},
300+
"directives":[
301+
{"isRepeatable":false,"name":"deprecated"},
302+
{"isRepeatable":true,"name":"foo"},
303+
{"isRepeatable":false,"name":"include"},
304+
{"isRepeatable":false,"name":"skip"}
305+
]}
306+
}

internal/wrapper/schema.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ func (s *Schema) Directives() []Directive {
5858
for _, d := range s.schema.Directives {
5959
res = append(res, s.directiveFromDef(d))
6060
}
61+
sort.Slice(res, func(i, j int) bool {
62+
return strings.Compare(res[i].Name, res[j].Name) < 0
63+
})
6164

6265
return res
6366
}
@@ -79,9 +82,10 @@ func (s *Schema) directiveFromDef(d *ast.DirectiveDefinition) Directive {
7982
}
8083

8184
return Directive{
82-
Name: d.Name,
83-
Description: d.Description,
84-
Locations: locs,
85-
Args: args,
85+
Name: d.Name,
86+
Description: d.Description,
87+
Locations: locs,
88+
Args: args,
89+
IsRepeatable: d.IsRepeatable,
8690
}
8791
}

internal/wrapper/wrapper.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import "github.com/gqlgo/gqlparser/v2/ast"
44

55
type (
66
Directive struct {
7-
Name string
8-
Description string
9-
Locations []string
10-
Args []InputValue
7+
Name string
8+
Description string
9+
Locations []string
10+
Args []InputValue
11+
IsRepeatable bool
1112
}
1213

1314
EnumValue struct {

0 commit comments

Comments
 (0)