apollographql / apollo-rs

Spec compliant GraphQL Tools in Rust.
Apache License 2.0
566 stars 43 forks source link

Add a graphql-js compatible-ish error serialization for Apollo Router #853

Closed goto-bus-stop closed 5 months ago

goto-bus-stop commented 5 months ago

With some additions to the error structures to pass through the data required.

This PR adds a .unstable_to_json_compat() function to diagnostics that returns best-effort error messages in the graphql-js format. Some things like "Did you mean?" are omitted intentionally. There are minor differences in a handful of other messages, but much fewer than before, and hopefully it'll be obvious to users that the meaning is the same. One example difference is the UnsupportedValueType message, which in graphql-js is a customisable type-specific validation, but in apollo-rs is a fixed check based only on what the spec knows about builtin scalars, so the error is a bit less specific.

The new API is only meant for use in the Apollo Router, temporarily, exempt from semver, and any other users will not be supported.