1

I need to get the child parameter value from Graphql.

Here is my Graphql query:

 {
  foods(type: "fries") {
    drinks {
      calorie(joule :1500) {
        name
      }
    }
  }
}

I can get the type field easily but also I need to get the joule value. When I investigate this problem I find a file called generated.go, so I found the following code part for sending parameters to the target function;

resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
    ctx = rctx // use context from middleware stack in children
    return storage.FoodFinder(rctx, args["type"].(string)) //only args sended to function.
})

I can get whole raw data from rctx variable but I don't wanna parse that, seems grueling.

So How can I get joule, one of that child fields from rctx context variable?

1 Answers1

0

so, on my case (i created audit logging for graphql queries) you can try to get root field context

rfc := graphql.GetRootFieldContext(ctx)
if rfc == nil {
    return next(ctx)
}

then you can catch children arguments:

for _, value := range rc.Field.Arguments {
    if value.Value.Children != nil {
        for _, v := range value.Value.Children {