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

[Data masking] Error when adding unmask warnings on interface types #12127

Closed
jerelmiller opened this issue Nov 14, 2024 · 3 comments · Fixed by #12130
Closed

[Data masking] Error when adding unmask warnings on interface types #12127

jerelmiller opened this issue Nov 14, 2024 · 3 comments · Fixed by #12130
Labels
🎭 data-masking Issues/PRs related to data masking
Milestone

Comments

@jerelmiller
Copy link
Member

jerelmiller commented Nov 14, 2024

Issue Description

Take the following query from the Spotify Showcase:

query PlaybackStateSubscriberQuery {
  me {
    player {
      playbackState {
        ...PlaybackStateFragment @unmask(mode: "migrate")
      }
    }
  }
}

fragment PlaybackStateFragment on PlaybackState {
  isPlaying
  repeatState
  shuffleState
  actions {
    disallows
  }
  context {
    uri
  }
  device {
    id
    name
    type
    volumePercent
  }
  item {
    id

    ... on Track {
      album {
        id
        images {
          url
        }
      }
    }

    ... on Episode {
      show {
        id
        images {
          url
        }
      }
    }
  }

  ...Playbar_playbackState @unmask(mode: "migrate")
}

When executing this query with data masking enabled, there is an error thrown:

Uncaught TypeError: Cannot read properties of undefined (reading 'id')

This happens when the item field returns a Track type. This is because the masking algorithm fails to check the inline fragment condition on the item before trying to add accessor warnings. In this case, the masking algorithm is trying to add warnings for the show field which should not happen because the fragment condition is unmatched.

We already handle this in the main part of the masking algorithm so we should be able to apply something similar here.

For now the workaround is to remove the mode: "migrate" argument from the @unmask directive to get this to work until we have a fix.

Link to Reproduction

https://github.com/apollographql/spotify-showcase/compare/jerel/masking-playground

Reproduction Steps

  • Run the spotify showcase with the above branch
  • Enable data masking in the client
  • Observe that the home page cannot load properly

@apollo/client version

3.12.0-rc.0

@jerelmiller
Copy link
Member Author

Fixed with #12130

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🎭 data-masking Issues/PRs related to data masking
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant