Skip to content

Accessing list of request fields #157

@dsoprea

Description

@dsoprea

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions