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

How to use custom resolver implementation #2974

Open
wheelerlaw opened this issue Mar 19, 2024 · 0 comments
Open

How to use custom resolver implementation #2974

wheelerlaw opened this issue Mar 19, 2024 · 0 comments

Comments

@wheelerlaw
Copy link

I am trying to figure out how to use an existing resolver implementation. But when I run go run github.com/99designs/gqlgen generate, it overwrites the implementation in the schema.resolvers.go file.

I am using this package to add pagination to my GraphQL server.

I add the following to my gqlgen.yaml file:

models:
  PageArgs:
    model: github.com/nrfta/go-paging.PageArgs

  PageInfo:
    model: github.com/nrfta/go-paging.PageInfo

This is what is inside my resolver.go:

package graph

//go:generate go run github.com/99designs/gqlgen generate

import (
	"github.com/nrfta/go-paging"
	"github.com/gobuffalo/pop/v6"
)

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

type Resolver struct {
	db *pop.Connection
}

func (r *Resolver) PageInfo() paging.PageInfoResolver {
	return paging.NewPageInfoResolver()
}

When I run go run github.com/99designs/gqlgen generate, I would expect my schema.resolvers.go to not contain the auto-generated pageInfoResolver struct PageInfo() method, since I have already provided an implementation. However, they get generated, and I get the following error:

validation failed: packages.Load: /home/wheeler/Repositories/.../graph/schema.resolvers.go:70:20: method Resolver.PageInfo already declared at /home/wheeler/Repositories/.../graph/resolver.go:18:20

exit status 1
graph/resolver.go:3: running "go": exit status 1

How do I get gqlgen to stop auto-generating the methods that return the sub-resolvers if the methods are already defined?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant