Skip to content

Commit

Permalink
Add tests for code persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Feb 3, 2020
1 parent 3e507e0 commit 93713a2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion codegen/config/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (r *ResolverConfig) Check() error {
if r.Filename == "" {
r.Filename = filepath.Join(r.DirName, "resolver.go")
} else {
r.Filename = filepath.Join(r.DirName, r.Filename)
r.Filename = abs(r.Filename)
}
default:
return fmt.Errorf("invalid layout %s. must be %s or %s", r.Layout, LayoutSingleFile, LayoutFollowSchema)
Expand Down
2 changes: 0 additions & 2 deletions internal/rewrite/rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ func (r *Rewriter) RemainingSource(filename string) string {
continue
}

fmt.Printf("%T\n", d)

buf.WriteString(r.getSource(d.Pos(), d.End()))
buf.WriteString("\n")
}
Expand Down
9 changes: 9 additions & 0 deletions plugin/resolvergen/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resolvergen

import (
"fmt"
"io/ioutil"
"syscall"
"testing"

Expand Down Expand Up @@ -41,6 +42,14 @@ func TestLayoutFollowSchema(t *testing.T) {

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

b, err := ioutil.ReadFile("testdata/followschema/out/schema_resolvers.go")
require.NoError(t, err)
source := string(b)

require.Contains(t, source, "// CustomerResolverType.Resolver implementation")
require.Contains(t, source, "// CustomerResolverType.Name implementation")
require.Contains(t, source, "// AUserHelperFunction implementation")
}

func assertNoErrors(t *testing.T, pkg string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This file will not be regenerated automatically.
//
// It serves as dependency injection for your app, add any dependencies you require here.
package customresolver

type CustomResolverType struct{}
17 changes: 14 additions & 3 deletions plugin/resolvergen/testdata/followschema/out/schema_resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ package customresolver

import (
"context"
"fmt"

customresolver "github.com/99designs/gqlgen/plugin/resolvergen/testdata/singlefile/out"
)

func (r *queryCustomResolverType) Resolver(ctx context.Context) (*customresolver.Resolver, error) {
panic(fmt.Errorf("not implemented"))
// CustomerResolverType.Resolver implementation
return nil, nil
}

func (r *resolverCustomResolverType) Name(ctx context.Context, obj *customresolver.Resolver) (string, error) {
panic(fmt.Errorf("not implemented"))
// CustomerResolverType.Name implementation
return "", nil
}

func (r *CustomResolverType) Query() customresolver.QueryResolver { return &queryCustomResolverType{r} }
Expand All @@ -24,3 +25,13 @@ func (r *CustomResolverType) Resolver() customresolver.ResolverResolver {

type queryCustomResolverType struct{ *CustomResolverType }
type resolverCustomResolverType struct{ *CustomResolverType }

// !!! WARNING !!!
// The code below was going to be deleted when updating resolvers. It has been copied here so you have
// one last chance to move it out of harms way if you want. There are two reasons this happens:
// - When renaming or deleting a resolver the old code will be put in here. You can safely delete
// it when you're done.
// - You have helper methods in this file. Move them out to keep these resolver files clean.
func AUserHelperFunction() {
// AUserHelperFunction implementation
}

0 comments on commit 93713a2

Please sign in to comment.