Skip to content

Commit

Permalink
add initial test
Browse files Browse the repository at this point in the history
  • Loading branch information
roneli committed Dec 2, 2023
1 parent d510647 commit 1bb2ce7
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 1 deletion.
24 changes: 24 additions & 0 deletions plugin/resolvergen/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ func TestOmitTemplateComment(t *testing.T) {
assertNoErrors(t, "github.com/99designs/gqlgen/plugin/resolvergen/testdata/omit_template_comment/out")
}

func TestResolver_Implementation(t *testing.T) {
_ = syscall.Unlink("testdata/resolver_implementor/resolver.go")

cfg, err := config.LoadConfig("testdata/resolver_implementor/gqlgen.yml")
require.NoError(t, err)
p := Plugin{}

require.NoError(t, cfg.Init())

data, err := codegen.BuildData(cfg, &implementorTest{})
if err != nil {
panic(err)
}

require.NoError(t, p.GenerateCode(data))
assertNoErrors(t, "github.com/99designs/gqlgen/plugin/resolvergen/testdata/resolver_implementor/out")
}

func TestCustomResolverTemplate(t *testing.T) {
_ = syscall.Unlink("testdata/resolvertemplate/out/resolver.go")
cfg, err := config.LoadConfig("testdata/resolvertemplate/gqlgen.yml")
Expand Down Expand Up @@ -142,3 +160,9 @@ func assertNoErrors(t *testing.T, pkg string) {
t.Fatal("see compilation errors above")
}
}

type implementorTest struct{}

func (i *implementorTest) Implement(field *codegen.Field) string {
return "panic(\"implementor implemented me\")"
}

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

15 changes: 15 additions & 0 deletions plugin/resolvergen/testdata/resolver_implementor/gqlgen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
schema:
- "testdata/schema.graphql"

exec:
filename: testdata/resolver_implementor/out/ignored.go
model:
filename: testdata/resolver_implementor/out/generated.go
resolver:
type: CustomResolverType
layout: follow-schema
dir: testdata/resolver_implementor/out

models:
Resolver:
model: github.com/99designs/gqlgen/plugin/resolvergen/testdata/resolver_implementor/out.Resolver
13 changes: 13 additions & 0 deletions plugin/resolvergen/testdata/resolver_implementor/out/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package customresolver

import "context"

type Resolver struct{}

type QueryResolver interface {
Resolver(ctx context.Context) (*Resolver, error)
}

type ResolverResolver interface {
Name(ctx context.Context, obj *Resolver) (string, error)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package customresolver

// This file will not be regenerated automatically.
//
// It serves as dependency injection for your app, add any dependencies you require here.

type CustomResolverType struct{}

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

0 comments on commit 1bb2ce7

Please sign in to comment.