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

feat: Implement @_unmask directives to unmask fragment types #31

Merged
merged 13 commits into from
Jan 22, 2024

Conversation

kitten
Copy link
Member

@kitten kitten commented Jan 22, 2024

Supersedes #28
Resolves #23

Summary

Fragments will now not be masked when they’re annotated with @_unmask. This will cause all their types derived by FragmentOf<> and in parent documents to be fully unwrapped and unmasked.

const fragment = graphql(`
  fragment TodoFields on Todo @_unmask {
    id
    text
  }
`);

//: { id: string | number, text: string }
type fragmentType = FragmentOf<typeof fragment>;

const query = graphql(`
  query {
    todo {
      ...TodoFields
    }
  }
`, [fragment]);

//: { todo: { id: string | number, text: string } }
type resultType = ResultOf<typeof fragment>;

This PR also improves the readability of the TodoDocumentNode generics. Instead of the third generic being a full fragment definition, it'll now be displayed with a different syntax, i.e.

{
  fragment: 'FragmentName',
  on: 'Type',
  masked: true
}

Set of changes

  • Refactor how reference types for definitions are used in selection types
  • Update type of fragment definition (i.e. $tada.definition)
  • Add support for @_unmask directive
  • Filter @_unmask directives from fragment definitions

Copy link

changeset-bot bot commented Jan 22, 2024

🦋 Changeset detected

Latest commit: 008c137

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

@kitten kitten changed the title Feat/simple fragment spread feat: Implement @unmask directives to unmask fragment types Jan 22, 2024
@kitten kitten changed the title feat: Implement @unmask directives to unmask fragment types feat: Implement @_unmask directives to unmask fragment types Jan 22, 2024
Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
@kitten kitten merged commit e064743 into main Jan 22, 2024
3 checks passed
@kitten kitten deleted the feat/simple-fragment-spread branch January 22, 2024 13:39
@github-actions github-actions bot mentioned this pull request Jan 22, 2024
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.

RFC: Allow to use the automatic types without fragment refs/masks
2 participants