Improve validation of URLPathTemplate and JSONSelection strings passed to @source{Type,Field} directives#2926
Conversation
|
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
| expect(getSelectionOutputShape(ast)).toEqual({ | ||
| foo: 'JSON', | ||
| barAlias: { | ||
| x: 'JSON', | ||
| y: 'JSON', | ||
| z: 'JSON', | ||
| }, |
There was a problem hiding this comment.
The output shape of a JSONSelection string is a tree of nested JSON dictionaries mirroring the structure of a GraphQL query, including scalar properties as leaf nodes. The ultimate goal is to validate this structure against object fields to ensure all fields in the schema are handled by some JSONSelection mapping.
These 'JSON' leaf values could have been any placeholder value, but I wanted to emphasize we can't assume much about the types of leaf fields within JSONSelection output shapes, except that they must be some JSON value (including possibly null for nullable fields).
Follow-up to #2910.
This work is not finished because we ultimately want to validate that the variables used by
URLPathTemplatestrings and the output shapes ofJSONSelectionstrings match the available field and argument names.This PR adds parsers for the two syntaxes and tests of those parsers, which allows us to validate the strings have the expected syntax, even if we're not validating semantics yet.
As another
TODO, when we useJSONSelectionforbodyparameters, it's the input shape of the selection that needs to be validated, rather than the output shape, sogetSelectionOutputShapemay not be sufficient.