-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JSONSelection] Support conditional ...
fragment selections
#6188
base: next
Are you sure you want to change the base?
Conversation
The LocatedSpan<T, X = ()> type supports an optional user-defined `extra: X` field, which we can use to smuggle meaningful custom error messages out of the parser.
✅ Docs Preview ReadyNo new or changed pages found. |
CI performance tests
|
Self::Spread(spread) => { | ||
let (spread_opt, spread_errors) = spread.apply_to_path(data, vars, input_path); | ||
errors.extend(spread_errors); | ||
if let Some(JSON::Object(spread)) = spread_opt { | ||
// TODO Better merge strategy for conflicting fields | ||
output.extend(spread); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling out this TODO
as a topic we've previously discussed, but that becomes more urgent with conditional fragments: how should we merge fields (potentially coming from different fragments, with different subselections) when they collide?
506a282
to
76949bd
Compare
In order to handle REST endpoints that return a union of possible result types, it's often necessary to consider various discriminator fields in the response, select different fields depending on those discriminator fields, and (when working with GraphQL) specify concrete
__typename
strings to resolve abstract types. This PR introduces a new JSONSelection syntax to address these use cases.To keep the new syntax unambiguous, a conditional fragment is always introduced by a
...
token, followed byif (expression) { included fields }
. Unconditional fragment spreads are not currently supported with this syntax. Optionally, additionalelse if
andelse
clauses may follow.In this example, we're using the runtime value of the
kind
field to determine which conditional fragment to apply:When working with GraphQL, this type discrimination syntax provides an easy place to specify concrete
__typename
strings based on thekind
values:In the future, we may want to extend this syntax to allow named fragments (to reduce repetition across
selection
strings), as in GraphQL, but that seemed too ambitious for this initial PR.