Skip to content

Allow separation of variable value coercion from the rest of execution #3679

Closed
@glasser

Description

@glasser

graphql-js lets you run the entire GraphQL operation with a single graphql function, or break it apart into different steps (parse, validate, execute) if you want a bit more control (for example, handling errors at different stages differently). However, the execute step is actually three steps combined into one:

  • Selecting the required operation from the document (execute is the first step that looks at the explicitly-provided operationName from the request)
  • Coercing variable values
  • Actual execution

Servers should be able to separate out these three steps and run them individually if they want. Specifically, it's likely that error handling should work differently for errors in the first two steps vs in the third. Apollo Server tries to provide a 400 HTTP status code for errors in the first two steps and a 200 for errors at execution time; this is also what the current GraphQL over HTTP spec suggests via a SHOULD, for response content-type application/graphql+json.

It's not too hard for a server to implement the first step manually, but differentiating between variable coercion errors and field errors is challenging. For example, Apollo Server has this hacky error-matching code.

Ideally, you would be able to choose between running execute and running three resolveOperation, coerceVariableValues, and executeResolvedOperation functions (passing return values from the previous functions to the next ones). This should be fully backwards-compatible since it's just adding a new API.

(I thought there was already an issue for this but I had trouble finding it.)

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