graphql-go / graphql-go/graphql
How to get rootQuery param on resolver of nested field
- Dominant language
- Go
- Stars
- 10.1k
- Forks
- 845
- PR merge metrics
- No merged PRs in 30d
Description
I have this structure:
```go
func rootQuery() *graphql.Object {
return graphql.NewObject(graphql.ObjectConfig{
Name: "RootQuery",
Fields: graphql.Fields{
"user": &graphql.Field{
Type: userType,
Args: graphql.FieldConfigArgument{
"id": &graphql.ArgumentConfig{
Type: graphql.String,
Description: "Find user by id",
},
"email": &graphql.ArgumentConfig{
Type: graphql.String,
Description: "Find user by email",
},
},
Resolve: FindUserResolver,
},
},
})
}
```
And this is the `userType` :
```go
var userType = graphql.NewObject(graphql.ObjectConfig{
Name: "User",
Fields: graphql.Fields{
"id": &graphql.Field{Type: graphql.String},
"email": &graphql.Field{Type: graphql.String},
"address": &graphql.Field{
Type: graphql.NewObject(graphql.ObjectConfig{
Name: "UserAddress",
Fields: graphql.Fields{
"state": &graphql.Field{
Type: graphql.NewObject(graphql.ObjectConfig{
Name: "StateDetails",
Fields: graphql.Fields{
"id": &graphql.Field{Type: graphql.Int},
"name": &graphql.Field{
Type: graphql.String,
Resolve: func (p *graphql.ResolveParams) (interface{}, error){
// I NEED USER ID OR USER EMAIL HERE
return nil, nil
}
},
"abbreviation": &graphql.Field{Type: graphql.String},
},
}),
},
},
}),
},
},
})
```
In Graphql spec we have this: http://graphql.org/learn/execution/#root-fields-resolvers
__"obj The previous object, which for a field on the root Query type is often not used."__
How I can get `id` or `email` field value on this `address->name` resolver ?
In `p *graphql.ResolveParams` we have params on sub level, not on root level.
Do we have something like `obj` to access to the previous object in this implementation?
Query example:
```
{
user(
id: "19966307-1505-4f1c-ba69-e8d1fcab1eda"),
{
address{
state{
name
}
}
}
}
```
Thanks.
Contributor guide
Assessment
This issue has not been assessed yet.