directive @isID on FIELD_DEFINITION
type Salesperson {
Name : String!
Age: Int!
UserID: Int! @isID
}
For something like this, with directive IsID how would you get 'UserID' as a string?
I can get the entire field with obj, or the value of UserID but that is not enough to infer 'UserID'
UserID: Int! @isID(FieldName:"UserID")
This seems to be the best I can do.
gqlgen version? v0.10.1-devgo version? go version go1.12.7 linux/amd64Hi @yuya-kanai 馃憢
You can't read this info in the ctx context.Context?
Thank you @JulienBreux
I guess it was mentioned here in the documentation.
I completely went past it.
This is the directive implementation
import ("github.com/99designs/gqlgen/graphql")
c.Directives.IsID = func(ctx context.Context, obj interface{}, next graphql.Resolver) (interface{}, error) {
ctxValue := graphql.GetResolverContext(ctx)
fmt.Printf("context: %#v\n", ctxValue)
}
Unfortunately this seems not to be working.
graphql.GetResolverContext(ctx).Object returns 'Salesperson' not 'UserID' and
graphql.CollectAllFields(ctx) returns an empty array.
Based on docs https://gqlgen.com/reference/directives/
- obj: the object containing the value this was applied to, eg:
for field definition directives, the object/input object that contains the field
for argument directives, a map containing all arguments
but I see in generated code that obj is always set as nil. Looks like it is a bug
@o1egl Thanks. Good to know it's a bug.
@vvakame Thank you for the label, also your MTC2018 blog was amazing (sorry for off topic)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hello,
Any upcoming news about this bug ?
Or is there any reason why the field name of the given directive shouldn't be visible from directive resolver ???