99designs / gqlgen

go generate based graphql server library
https://gqlgen.com
MIT License
9.9k stars 1.15k forks source link

error: directive entityResolver is not implemented #3267

Closed hboylan closed 2 weeks ago

hboylan commented 3 weeks ago

What happened?

Trying to use the @entityResolver(multi: true) directive. The multi entity resolver is generated properly, but any requests to it yield a directive error.

What did you expect?

Should be able to resolve multi entity.

Minimal graphql.schema and models to reproduce

https://github.com/hboylan/gqlgen-multi-entity-resolver

operation:

query Test {
  todos {
    id
  }
}

response:

{
  "errors": [
    {
      "message": "directive entityResolver is not implemented",
      "path": [
        "todos"
      ]
    }
  ],
  "data": null
}

versions

StevenACoffman commented 2 weeks ago

Yeah, that error is misleading! If you upgrade to v0.17.54 you can get a more reasonable stacktrace that points you to what the actual problem is.

Either way, you just need to implement your resolvers. If you edit graph/schema.resolvers.go and implement the Todos:

// Todos is the resolver for the todos field.
func (r *queryResolver) Todos(ctx context.Context) ([]*model.Todo, error) {
    todo := &model.Todo{
        ID:   "Something",
        Text: "Do something",
        Done: false,
        User: &model.User{
            ID:   "one",
            Name: "Bob",
        },
    }
    return []*model.Todo{todo}, nil
}

Then your query actually works!

StevenACoffman commented 2 weeks ago

@dericcain @wshirey @chiijlaw You all gave thumbs up, so I assume you are either encountering the same problem or working together. Does this explanation help you all?

hboylan commented 1 week ago

If you upgrade to v0.17.54 you can get a more reasonable stacktrace that points you to what the actual problem is.

Sorry about the hasty example here. The upgrade to v0.17.54 fixed the error in our actual project. Thank you!