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

Fix 1955: only print message on @key found on interfaces #1956

Merged
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
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