Skip to content

Commit

Permalink
Fix 1955: only print message on @key found on interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
carldunham committed Feb 8, 2022
1 parent 9262b35 commit 3623f20
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 14 deletions.
8 changes: 6 additions & 2 deletions plugin/federation/federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,14 @@ func isFederatedEntity(schemaType *ast.Definition) ([]*ast.Directive, bool) {
case ast.Interface:
// TODO: support @key and @extends for interfaces
if dir := schemaType.Directives.ForName("key"); dir != nil {
panic("@key directive is not currently supported for interfaces.")
fmt.Printf("@key directive found on \"interface %s\". Will be ignored.\n", schemaType.Name)
}
if dir := schemaType.Directives.ForName("extends"); dir != nil {
panic("@extends directive is not currently supported for interfaces.")
panic(
fmt.Sprintf(
"@extends directive is not currently supported for interfaces, use \"extend interface %s\" instead.",
schemaType.Name,
))
}
default:
// ignore
Expand Down
12 changes: 10 additions & 2 deletions plugin/federation/federation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,17 @@ func TestNoEntities(t *testing.T) {
require.Len(t, f.Entities, 0)
}

func TestInterfaces(t *testing.T) {
func TestInterfaceKeyDirective(t *testing.T) {
f, cfg := load(t, "testdata/interfaces/key.yml")

err := f.MutateConfig(cfg)
require.NoError(t, err)
require.Len(t, f.Entities, 0)
}

func TestInterfaceExtendsDirective(t *testing.T) {
require.Panics(t, func() {
load(t, "testdata/interfaces/gqlgen.yml")
load(t, "testdata/interfaces/extends.yml")
})
}

Expand Down
11 changes: 11 additions & 0 deletions plugin/federation/testdata/interfaces/extends.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
interface Hello @extends {
name: String!
secondary: String!
}

extend type World implements Hello @key(fields: "name") {
name: String! @external
secondary: String!

tertiary: String!
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
schema:
- "testdata/interfaces/interfaces.graphqls"
- "testdata/interfaces/extends.graphqls"
exec:
filename: testdata/interfaces/generated/exec.go
federation:
Expand Down
9 changes: 0 additions & 9 deletions plugin/federation/testdata/interfaces/interfaces.graphqls

This file was deleted.

4 changes: 4 additions & 0 deletions plugin/federation/testdata/interfaces/key.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extend interface Hello @key(fields: "name") {
name: String!
secondary: String!
}
6 changes: 6 additions & 0 deletions plugin/federation/testdata/interfaces/key.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
schema:
- "testdata/interfaces/key.graphqls"
exec:
filename: testdata/interfaces/generated/exec.go
federation:
filename: testdata/interfaces/generated/federation.go

0 comments on commit 3623f20

Please sign in to comment.