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

use "embed" in generated code #2119

Merged
merged 8 commits into from
May 5, 2022
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
37 changes: 11 additions & 26 deletions _examples/chat/generated.go

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

47 changes: 13 additions & 34 deletions _examples/config/generated.go

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

42 changes: 11 additions & 31 deletions _examples/dataloader/generated.go

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

3 changes: 3 additions & 0 deletions _examples/embedding/parent.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extend type Query {
parentdir: String!
}
12 changes: 12 additions & 0 deletions _examples/embedding/subdir/cfgdir/generate_in_gendir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
schema:
- schemadir/*.graphqls
- ../*.graphqls
- '*.graphqls'
exec:
dir: gendir
filename: gendir/generated.go
package: gendir

model:
filename: gendir/model.go
package: gendir
12 changes: 12 additions & 0 deletions _examples/embedding/subdir/cfgdir/generate_in_subdir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
schema:
- schemadir/*.graphqls
- ../*.graphqls
- '*.graphqls'
exec:
layout: follow-schema
dir: .
package: subdir

model:
filename: model.go
package: subdir
48 changes: 48 additions & 0 deletions _examples/embedding/subdir/embedding_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package subdir

import (
"testing"

"github.com/99designs/gqlgen/_examples/embedding/subdir/gendir"
"github.com/99designs/gqlgen/client"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/stretchr/testify/require"
)

func TestEmbeddingWorks(t *testing.T) {
c := client.New(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: &Resolver{}})))
var resp struct {
InSchemadir string
Parentdir string
Subdir string
}
c.MustPost(`{
inSchemadir
parentdir
subdir
}
`, &resp)

require.Equal(t, "example", resp.InSchemadir)
require.Equal(t, "example", resp.Parentdir)
require.Equal(t, "example", resp.Subdir)
}

func TestEmbeddingWorksInGendir(t *testing.T) {
c := client.New(handler.NewDefaultServer(gendir.NewExecutableSchema(gendir.Config{Resolvers: &GendirResolver{}})))
var resp struct {
InSchemadir string
Parentdir string
Subdir string
}
c.MustPost(`{
inSchemadir
parentdir
subdir
}
`, &resp)

require.Equal(t, "example", resp.InSchemadir)
require.Equal(t, "example", resp.Parentdir)
require.Equal(t, "example", resp.Subdir)
}
Loading