graphql-go / graphql-go/graphql

Accessing list of request fields

Open
#157 15 comments 13 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
10.1k
Forks
845
PR merge metrics
No merged PRs in 30d

Description

What's the correct way to determine what data needs to be constructed and returned? Obviously, some fields might have a higher cost to populate than others. This is a resolve function:

```
(*fields)["Classifier"] = &graphql.Field{
Type: classifierType,
Args: graphql.FieldConfigArgument{
"uuid": &graphql.ArgumentConfig{
Type: graphql.ID,
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
uuid := p.Args["uuid"].(string)
```

This is `ResolveParams`:

```
type ResolveParams struct {
// Source is the source value
Source interface{}

// Args is a map of arguments for current GraphQL request
Args map[string]interface{}

// Info is a collection of information about the current execution state.
Info ResolveInfo

// Context argument is a context value that is provided to every resolve function within an execution.
// It is commonly
// used to represent an authenticated user, or request-specific caches.
Context context.Context
}
```

The only immediately interesting field here is `ResolveInfo`, but it, too, doesn't seem to provide the requested fields:

```
type ResolveInfo struct {
FieldName string
FieldASTs []*ast.Field
ReturnType Output
ParentType Composite
Schema Schema
Fragments map[string]ast.Definition
RootValue interface{}
Operation ast.Definition
VariableValues map[string]interface{}
}
```

Thanks.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.