You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following example, I want to resolve the value in C, but I need the IDs of both A and B to do it. p.Source only gives me B, but not A. What is the proper way to solve this problem?
vara=graphql.NewObject(graphql.ObjectConfig{
Name: "A",
Fields: graphql.Fields{
"id": &graphql.Field{Type: graphql.String},
"b": &graphql.Field{Type: graphql.NewObject(graphql.ObjectConfig{
Name: "B",
Fields: graphql.Fields{
"id": &graphql.Field{Type: graphql.String},
"c": &graphql.Field{Type: graphql.NewObject(graphql.ObjectConfig{
Name: "C",
Fields: graphql.Fields{
"value": &graphql.Field{
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
// I need the ID of A to resolve the value of Creturnnil, nil
},
},
},
})},
},
})},
},
})
The text was updated successfully, but these errors were encountered:
You should be able to handle this using Go's context.Context type. See this explanation:
One benefit of using context.Context in a program is the ability to access data stored inside a context. By adding data to a context and passing the context from function to function, each layer of a program can add additional information about what’s happening.
In other words, you can have resolvers A and B add their IDs to the context, and then resolver C can look up those IDs. I hope this helps, and others can correct me if there's a better pattern.
In the following example, I want to resolve the
value
inC
, but I need the IDs of bothA
andB
to do it.p.Source
only gives meB
, but notA
. What is the proper way to solve this problem?The text was updated successfully, but these errors were encountered: