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

Binding a GraphQL Any field to a Go struct method returning *any doesn't work #2643

Closed
Tooni opened this issue May 23, 2023 · 0 comments
Closed

Comments

@Tooni
Copy link
Contributor

Tooni commented May 23, 2023

What happened?

the generation (go run github.com/99designs/gqlgen generate) errors out with

validation failed: packages.Load: /Users/tooni/qubit/gqlgen-todos3/graph/generated.go:2897:9: cannot use res (variable of type interface{}) as *any value in return statement: interface{} does not implement *any (type *any is pointer to interface, not interface)

because this invalid code is produced in generated.go

func (ec *executionContext) unmarshalOAny2ᚖinterface(ctx context.Context, v interface{}) (*any, error) {
	if v == nil {
		return nil, nil
	}
	res, err := graphql.UnmarshalAny(v)
	return res, graphql.ErrorOnPath(ctx, err)
}

What did you expect?

non-erroring code. maybe just &res in the return?

in v0.10.2, which is what i was trying to update from, this was the generated code for the same function

func (ec *executionContext) unmarshalOAny2ᚖinterface(ctx context.Context, v interface{}) (*any, error) {
	if v == nil {
		return nil, nil
	}
	res, err := ec.unmarshalOAny2interface(ctx, v)
	return &res, err
}

Minimal graphql.schema and models to reproduce

schema.graphqls

scalar Any

type ContentHaver {
  id: ID!
  content: Any
}

model.go

package model

type ContentHaver struct {
	ID          string
	ContentJSON *any
}

func (c *ContentHaver) Content() *any {
	return c.ContentJSON
}

gqlgen.yml

schema:
  - graph/*.graphqls

exec:
  filename: graph/generated.go
  package: graph

model:
  filename: graph/model/models_gen.go
  package: model

resolver:
  dir: graph
  package: graph
  filename: resolvers.go

models:
  ContentHaver:
    model: github.com/tooni/gqlgen-todos/graph/model.ContentHaver

versions

  • go run github.com/99designs/gqlgen version?
    v0.17.31
  • go version?
    go version go1.20.3 darwin/arm64
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