graphql-go / graphql-go/graphql
Accessing parent from nested child resolver
- Dominant language
- Go
- Stars
- 10.1k
- Forks
- 845
- PR merge metrics
- No merged PRs in 30d
Description
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?
```go
var a = 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 C
return nil, nil
},
},
},
})},
},
})},
},
})
```
Contributor guide
Assessment
This issue has not been assessed yet.