We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I'm getting a compiler error when gqlgen creates resolvers based on a field that has a wrapped builtin type. For example:
schema.graphql
schema { query: Query } type Query { foo: Foo } type Foo { id: String! }
model.go
package tmp type Identifier string type Foo struct { ID Identifier }
types.json
{ "Foo": "tmp.Foo" }
$ gqlgen -out gen.go $ go build # tmp ./gen.go:84:41: cannot use res (type Identifier) as type string in argument to graphql.MarshalString
Because the generated function uses MarshalString(res) instead of MarshalString(string(res)):
MarshalString(res)
MarshalString(string(res))
// nolint: gocyclo, errcheck, gas, goconst func (ec *executionContext) _foo(sel []query.Selection, it *Foo) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, fooImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Foo") case "id": badArgs := false if badArgs { continue } res := it.ID out.Values[i] = graphql.MarshalString(res) // <-- invalid call default: panic("unknown field " + strconv.Quote(field.Name)) } } return out }
The text was updated successfully, but these errors were encountered:
Interesting, I wasn't expecting it to be used quite like that. It probably should work like that, I'll take a look this afternoon.
In the mean time, you can add the (un)marshalGQL methods to your user type.
eg: https://github.com/vektah/gqlgen/blob/master/example/scalars/model.go#L21-L52
Sorry, something went wrong.
Ah, I hadn't noticed that workaround before, thanks!
No branches or pull requests
I'm getting a compiler error when gqlgen creates resolvers based on a field that has a wrapped builtin type. For example:
schema.graphql
model.go
types.json
Because the generated function uses
MarshalString(res)
instead ofMarshalString(string(res))
:The text was updated successfully, but these errors were encountered: