-
Notifications
You must be signed in to change notification settings - Fork 493
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
mixed concrete types with pointer receivers are unsupported. #323
Comments
As far as I understand it, when a type is nullable in the GraphQL schema, then it needs to be a pointer in Golang. Am I missing something? |
Nullability doesn't really come into play here. If you want to represent a null slice, you just set it to null. While you can have a schema with nullable elements, it doesn't make a lot of sense in practice. In the case of this schema, the elements are not declared as nullable, so allowing a concrete resolver should be allowed. Put into an example, we should be able have the following work, without modifying the type of the receiver:
With the above, we have a This lets us avoid copying for method calls and control nullability. |
Well, how often do you need nullable and non-nullable version of the same resolver in the same schema? Again, the fact that it hasn't happened to me doesn't mean that it is not a real issue.
How does this let us control nullability? I am still not convinced that this is a real issue. |
I ran into the same situation. I tried to implement a schema with non-nullable resolvers, but had to re-implement my resolver's pointer receivers as value receivers, which comes with performance hits. |
@jbacon out of curiosity what was the performance hit? Also, why did you have to change the resolver's pointer receivers? You could as well dereference the pointer in the resolver. |
just ran into a similar problem - an example below
resolver:
Everything above works fine. However, if we I want to add a second query which returns non-nullable type
I get the following error:
In my project, I ran into this problem with some custom scalar involved and got a super vague panic message - took me a while to find out this root cause Since GoLang makes the pointer receiver method accessible to both pointer & concrete types, I think it should be the same behavior for resolving both nullable & non-nullable fields in graphql. To rephrase: I think ideally the method on pointer type can also be resolved by concrete type. @pavelnikolov do you think it makes sense? If so, I can start looking into making the update |
I have a resolver returning a list of resolvers like this:
When I try to query with the schema above, I get an error like this:
The code mapping these types shouldn't care whether or not there is a pointer when validating if a type implements an interface. Since my resolvers are shallow types, leaving them concrete in the struct will reduce pointer lookups. However, I'd like to use a pointer receiver on these methods to avoid the copy for each method.
To make this code work with a pointer receiver, I'd have to return a slice of pointers, which doesn't really make a whole lot of sense, unless there is expense to copying the type or they are shared in some way.
There are two points of inefficiency:
While these seem like small issues, they can contribute to performance problems by generating additional allocations and slow performance on cache line misses.
It looks like the issue is
graphql-go/internal/exec/resolvable/resolvable.go
Line 233 in e582242
The text was updated successfully, but these errors were encountered: