Skip to content
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

Improve validation of URLPathTemplate and JSONSelection strings passed to @source{Type,Field} directives #2926

Draft
wants to merge 6 commits into
base: benjamn/fix-@sourceField-validation-on-extend-type
Choose a base branch
from

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Feb 1, 2024

Follow-up to #2910.

This work is not finished because we ultimately want to validate that the variables used by URLPathTemplate strings and the output shapes of JSONSelection strings 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 use JSONSelection for body parameters, it's the input shape of the selection that needs to be validated, rather than the output shape, so getSelectionOutputShape may not be sufficient.

@benjamn benjamn self-assigned this Feb 1, 2024
Copy link

changeset-bot bot commented Feb 1, 2024

⚠️ No Changeset found

Latest commit: 0fc0d11

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

codesandbox-ci bot commented Feb 1, 2024

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.

Comment on lines +79 to +85
expect(getSelectionOutputShape(ast)).toEqual({
foo: 'JSON',
barAlias: {
x: 'JSON',
y: 'JSON',
z: 'JSON',
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant