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

add federation tests #1719

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
22 changes: 22 additions & 0 deletions plugin/federation/federation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package federation
import (
"testing"

"github.com/99designs/gqlgen/codegen"
"github.com/99designs/gqlgen/codegen/config"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -77,6 +78,27 @@ func TestNoEntities(t *testing.T) {
require.Len(t, f.Entities, 0)
}

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

func TestCodeGeneration(t *testing.T) {
f, cfg := load(t, "testdata/allthethings/gqlgen.yml")

require.Len(t, cfg.Schema.Types["_Entity"].Types, 6)
require.Len(t, f.Entities, 6)

require.NoError(t, f.MutateConfig(cfg))

data, err := codegen.BuildData(cfg)
if err != nil {
panic(err)
}
require.NoError(t, f.GenerateCode(data))
}

func load(t *testing.T, name string) (*federation, *config.Config) {
t.Helper()

Expand Down
256 changes: 256 additions & 0 deletions plugin/federation/testdata/allthethings/generated/federation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

extend interface World {
foo: String! @external
bar: Int!
}