diff --git a/apollo-federation/src/sources/connect/json_selection/README.md b/apollo-federation/src/sources/connect/json_selection/README.md index f80a78b89d3..d2e99b4c32b 100644 --- a/apollo-federation/src/sources/connect/json_selection/README.md +++ b/apollo-federation/src/sources/connect/json_selection/README.md @@ -834,6 +834,55 @@ Also, as a minor syntactic convenience, `LitObject` literals can have `Identifier` or `LitString` keys, whereas JSON objects can have only double-quoted string literal keys. +### `LitPath ::=` + +![LitPath](./grammar/LitPath.svg) + +A `LitPath` is a special form of `PathSelection` (similar to `VarPath`, +`KeyPath`, `AtPath`, and `ExprPath`) that can be used _only_ within `LitExpr` +expressions, allowing the head of the path to be any `LitExpr` value, with a +non-empty tail of `PathStep` items afterward: + +```graphql +object: $({ + sd: "asdf"->slice(1, 3), + sum: 1234->add(5678), + celsius: 98.6->sub(32)->mul(5)->div(9), + nine: -1->add(10), + false: true->not, + true: false->not, + twenty: { a: 1, b: 2 }.b->mul(10), + last: [1, 2, 3]->last, + justA: "abc"->first, + justC: "abc"->last, +}) +``` + +Note that expressions like `true->not` and `"asdf"->slice(1, 3)` have a +different interpretation in the default selection syntax (outside of `LitExpr` +parsing), since `true` and `"asdf"` will be interpreted as field names there, +not as literal values. If you want to refer to a quoted field value within a +`LitExpr`, you can use the `$.` variable prefix to disambiguate it: + +```graphql +object: $({ + fieldEntries: $."quoted field"->entries, + stringPrefix: "quoted field"->slice(0, "quoted"->size), +}) +``` + +You can still nest the `$(...)` inside itself (or use it within `->` method +arguments), as in + +```graphql +justA: $($("abc")->first) +nineAgain: $($(-1)->add($(10))) +``` + +In these examples, only the outermost `$(...)` wrapper is required, though the +inner wrappers may be used to clarify the structure of the expression, similar +to parentheses in other languages. + ### `LitPrimitive ::=` ![LitPrimitive](./grammar/LitPrimitive.svg) diff --git a/apollo-federation/src/sources/connect/json_selection/grammar/LitExpr.svg b/apollo-federation/src/sources/connect/json_selection/grammar/LitExpr.svg index 200f1d9bb60..05a3798e395 100644 --- a/apollo-federation/src/sources/connect/json_selection/grammar/LitExpr.svg +++ b/apollo-federation/src/sources/connect/json_selection/grammar/LitExpr.svg @@ -1,5 +1,5 @@ - + + + + + LitPath + - - - LitPrimitive + + + LitPrimitive - - - LitObject + + + LitObject - - - LitArray + + + LitArray - - - PathSelection + + + PathSelection + d="m17 17 h2 m20 0 h10 m64 0 h10 m0 0 h42 m-146 0 h20 m126 0 h20 m-166 0 q10 0 10 10 m146 0 q0 -10 10 -10 m-156 10 v24 m146 0 v-24 m-146 24 q0 10 10 10 m126 0 q10 0 10 -10 m-136 10 h10 m90 0 h10 m0 0 h16 m-136 -10 v20 m146 0 v-20 m-146 20 v24 m146 0 v-24 m-146 24 q0 10 10 10 m126 0 q10 0 10 -10 m-136 10 h10 m76 0 h10 m0 0 h30 m-136 -10 v20 m146 0 v-20 m-146 20 v24 m146 0 v-24 m-146 24 q0 10 10 10 m126 0 q10 0 10 -10 m-136 10 h10 m68 0 h10 m0 0 h38 m-136 -10 v20 m146 0 v-20 m-146 20 v24 m146 0 v-24 m-146 24 q0 10 10 10 m126 0 q10 0 10 -10 m-136 10 h10 m106 0 h10 m23 -176 h-3"/> diff --git a/apollo-federation/src/sources/connect/json_selection/grammar/LitPath.svg b/apollo-federation/src/sources/connect/json_selection/grammar/LitPath.svg new file mode 100644 index 00000000000..670f5a19272 --- /dev/null +++ b/apollo-federation/src/sources/connect/json_selection/grammar/LitPath.svg @@ -0,0 +1,66 @@ + + + + + + + + + + + LitPrimitive + + + + + LitObject + + + + + LitArray + + + + + PathStep + + + + +