apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
https://apollographql.com/client
MIT License
19.34k stars 2.66k forks source link

[Data masking] Add `@unmask` directive with field access warnings #11919

Closed jerelmiller closed 2 months ago

jerelmiller commented 3 months ago

Closes https://github.com/apollographql/apollo-client/issues/11674 Closes https://github.com/apollographql/apollo-client/issues/11673

Adds support for an @unmask directive that disables data masking for a named fragment when data masking is enabled in the client.

query {
  currentUser {
    id
    ...UserFields @unmask
  }
}

fragment UserFields on User {
  name
}

This directive will be most useful for migration when adopting data masking. As such, we've added the ability to emit warnings when using a mode argument set to migrate:

query {
  currentUser {
    id
    ...UserFields @unmask(mode: "migrate")
  }
}

fragment UserFields on User {
  name
}

When accessing data.currentUser.name, the user will see a warning in the console about accessing an unmasked field. Using @unmask without the mode argument won't emit warnings.

It is also possible to mix and match fragment subtrees with @unmask which allows a user to migrate a subtree at a time.

query {
  currentUser {
    ...UserFields @unmask(mode: "migrate")
  }
}

fragment UserFields on User {
  # will be masked
  ...UserSubfields

  # will emit warnings
  ...UserSubfields2 @unmask(mode: "migrate")

  # data will be available without warnings
  ...UserSubfields3 @unmask
}
changeset-bot[bot] commented 3 months ago

⚠️ No Changeset found

Latest commit: a924c0f8e8955c792c08b8906c35493bde85b590

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

jerelmiller commented 2 months ago

Moving back to draft after discussion with @phryneas. Will put it back up for review after changes are made.