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

v7 enhance(utils) expand filterSchema #2005

Merged
merged 42 commits into from Sep 21, 2020
Merged

Conversation

gmac
Copy link
Contributor

@gmac gmac commented Sep 6, 2020

This enhances the utils/filterSchema method to make it more general purpose and efficient. Right now the method is not quite granular enough to be useful for access control filtering. This updates the method as follows:

  • Adds dedicated filters for object fields, interface fields, and input fields; while leaving one general purpose field filter option that will operate across all three.

  • Adds argument filtering, which is extremely useful when performing access control on a schema for certain audiences.

  • Makes all but the type filter optional. When a filter is omitted, the method skips churning through that set of work.

Release Notes

BREAKING – filterSchema(fieldFilter) option will now filter ALL fields across Object, Interface, and Input types. For the previous Object-only behavior, switch to the objectFieldFilter option.

TODO:

  • If this PR is a new feature, reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass

yaacovCR and others added 19 commits September 4, 2020 14:53
This is not the optimal way to address ardatan#1047 but is the most backwards
compatible.
includes also changes to transform method arguments
see ardatan#1614
* implicit pruning from healSchema and mapSchema can sometimes be dangerous: e.g.  empty interfaces are valid for later extension.
* the pruneSchema utility functions (and PruneSchema transform) can be explicitly used to prune as desired

See: ardatan#1817
* removes support for createMergedResolver and ExtendSchema transform in favor of visitResult, simplifying the refactoring.
move typesContainSelectionSet to delegate package
remove typeContainsSelectionSet
Previously, errors with invalid or missing paths were lost.
See:
ardatan#1641
https://github.com/apollographql/apollo-server/issues/4226

They are now saved!

All correctly pathed errors are now inlined into the returned data by the CheckResultAndHandleErrors transform.

The data is now annotated only with the remaining "unpathed" errors. These are then returned when possible if a null is encountered including the missing or potentially invalid path.

Changes to error handling obviate some existing functions including getErrorsByPathSegment, getErrors in favor of getUnpathedErrors.

Utility functions including slicedError and unreleased functions extendedError and unextendedError are no longer necessary.
we could consider later adding support for $$asyncIterable similar to upstream graphql-js, but this would have to be across the entire codebase, which currently supports only Symbol.asyncIterator.
use delegationContext within delegation transforms
remove fragment hints and transforms in favor of selection set hints and transforms
prune fragment functions from utils package
@gmac
Copy link
Contributor Author

gmac commented Sep 9, 2020

@yaacovCR would you be onboard with this as part of v7? We use this behavior at Vox Media, would be nice to backfill it into the base package. Type/field/arg filtering is really useful when whitelisting parts of a schema based on access level.

This is not the optimal way to address ardatan#1047 but is the most backwards
compatible.
includes also changes to transform method arguments
see ardatan#1614
* implicit pruning from healSchema and mapSchema can sometimes be dangerous: e.g.  empty interfaces are valid for later extension.
* the pruneSchema utility functions (and PruneSchema transform) can be explicitly used to prune as desired

See: ardatan#1817
* removes support for createMergedResolver and ExtendSchema transform in favor of visitResult, simplifying the refactoring.
move typesContainSelectionSet to delegate package
remove typeContainsSelectionSet
Previously, errors with invalid or missing paths were lost.
See:
ardatan#1641
https://github.com/apollographql/apollo-server/issues/4226

They are now saved!

All correctly pathed errors are now inlined into the returned data by the CheckResultAndHandleErrors transform.

The data is now annotated only with the remaining "unpathed" errors. These are then returned when possible if a null is encountered including the missing or potentially invalid path.

Changes to error handling obviate some existing functions including getErrorsByPathSegment, getErrors in favor of getUnpathedErrors.

Utility functions including slicedError and unreleased functions extendedError and unextendedError are no longer necessary.
we could consider later adding support for $$asyncIterable similar to upstream graphql-js, but this would have to be across the entire codebase, which currently supports only Symbol.asyncIterator.
use delegationContext within delegation transforms
remove fragment hints and transforms in favor of selection set hints and transforms
prune fragment functions from utils package
@yaacovCR
Copy link
Collaborator

yaacovCR commented Sep 13, 2020

Can you rebase on master now that #1989 merged

@changeset-bot
Copy link

changeset-bot bot commented Sep 14, 2020

💥 No Changeset

Latest commit: e2d93fe

Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂

If these changes should be published to npm, you need to add a changeset.

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

@gmac
Copy link
Contributor Author

gmac commented Sep 14, 2020

Not sure what's going on with branching here... a rebase encounters all kinds of conflicts, and I'm not sure why. This is at least the intended diff, though commit history looks weird.

@yaacovCR yaacovCR changed the base branch from v7 to master September 21, 2020 14:22
@yaacovCR yaacovCR changed the base branch from master to v7 September 21, 2020 14:22
@yaacovCR yaacovCR merged commit bb7bd64 into ardatan:v7 Sep 21, 2020
yaacovCR pushed a commit that referenced this pull request Sep 21, 2020
* updated filter schema.

* update existing usage.
yaacovCR pushed a commit that referenced this pull request Sep 30, 2020
* updated filter schema.

* update existing usage.
yaacovCR pushed a commit that referenced this pull request Oct 1, 2020
* updated filter schema.

* update existing usage.
yaacovCR pushed a commit that referenced this pull request Oct 6, 2020
* updated filter schema.

* update existing usage.
yaacovCR pushed a commit that referenced this pull request Oct 23, 2020
* updated filter schema.

* update existing usage.
@gmac gmac deleted the gm-v7-filter-schema branch January 8, 2021 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants