Add __assertStep support to makeGrafastSchema and makeExtendSchemaPlugin #1916
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Relates to #1915 (but doesn't fix it).
Object types in Grafast can indicate that they must be represented by a particular step or set of steps; this can help to catch bugs early. For example, in PostGraphile a database table resource should be represented by a
pgSelectSingle
or similar class; representing it withobject({id: 1})
or similar would mean the step doesn't have the expected helper methods and downstream fields may fail to plan because their expectations are broken.When writing a schema manually, you set this via
objectTypeConfig.extensions.grafast.assertStep
which can either be a step class itself (e.g.objectTypeConfig.extensions = {grafast: {assertStep: PgSelectSingleStep}}
) or it can be an "assertion function" that throws an error if the passed step is not of the right type, e.g.:Further, if you have a union (e.g.
union U = A | B | C
) then all types in the union must either expect a plan, or not expect a plan.Previous to this PR, you could not indicate that your custom type created in makeExtendSchemaPlugin expects a plan. Further, the types of makeGrafastSchema were wrong, filing this under the removed
__Step
property. This PR makes it so that you can define__assertStep
as part of defining the field plans for an object type; the__
prefix ensures that it cannot conflict with any field names (since GraphQL forbids field names that start with__
). E.g.:Performance impact
Negligible.
Security impact
None known.
Checklist
yarn lint:fix
passes.yarn test
passes.RELEASE_NOTES.md
file (if one exists).If this is a breaking change I've explained why.