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

Add support for Relay 13+ generated code by adding $fragmentSpreads support #88

Merged
merged 3 commits into from
Dec 15, 2023

Conversation

Markionium
Copy link
Member

Relay 16 generates the following fragment type

export type JobTitleFragment$key = {
  readonly " $data"?: JobTitleFragment$data;
  readonly " $fragmentSpreads": FragmentRefs<"JobTitleFragment">;
};

Our hooks currently only support the older " $fragmentRefs" format that looks as follows.

export type JobTitleFragment$key = {
  readonly " $data"?: JobTitleFragment$data;
  readonly " $fragmentRefs": FragmentRefs<"JobTitleFragment">;
};

This means that when generating code with newer versions of the relay-compiler we can not use those generated fragments with useFragment and will get the following error.

Argument of type 'JobTitleFragment$key' is not assignable to parameter of type 'Readonly<{ " $data"?: unknown; " $fragmentRefs": unknown; }>'.
  Property '" $fragmentRefs"' is missing in type 'JobTitleFragment$key' but required in type 'Readonly<{ " $data"?: unknown; " $fragmentRefs": unknown; }>'.ts(2345)
types.d.ts(32, 5): '" $fragmentRefs"' is declared here.

This PR adds support for both variants which makes useFragment compatible with with Relay types < 13 and Relay > 13.

Copy link
Member

@alloy alloy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

@alloy alloy merged commit 653e625 into microsoft:main Dec 15, 2023
2 checks passed
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.

3 participants