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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions change/@nova-react-8a6bad44-a7eb-4078-8e64-97d0eaeedc62.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Add support for $fragmentSpreads format",
"packageName": "@nova/react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
17 changes: 17 additions & 0 deletions packages/nova-react/src/graphql/hooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@ describe(useFragment, () => {
useFragment(fragment, opaqueFragmentRef);
void _;
});

it("supports the $fragmentSpreads format that is generated from Relay 13", () => {
type SomeFragment$data = { someKey: string };
type SomeFragment$key = {
readonly " $data"?: SomeFragment$data;
readonly " $fragmentSpreads": FragmentRefs<"SomeFragment">;
};

const fragment = {} as unknown as GraphQLTaggedNode;
const opaqueFragmentRef = {} as unknown as SomeFragment$key;

// This test just checks that there are no TS errors. Alas the test suite currently won't fail if that were the
// case, but at least there's a test that covers the intent.
const _: () => SomeFragment$data = () =>
useFragment(fragment, opaqueFragmentRef);
void _;
});
});

describe(useRefetchableFragment, () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/nova-react/src/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export interface _RefType<Ref extends string> {
" $refType": Ref;
}

export interface _FragmentRefs<Refs extends string> {
export type _FragmentRefs<Refs extends string> = {
" $fragmentRefs": FragmentRefs<Refs>;
} | {
" $fragmentSpreads": FragmentRefs<Refs>;
}

// This is used in the actual artifacts to define the various fragment references a container holds.
Expand All @@ -44,6 +46,9 @@ export type FragmentReference = unknown;
export type KeyType<TData = unknown> = Readonly<{
" $data"?: TData;
" $fragmentRefs": FragmentReference;
}> | Readonly<{
" $data"?: TData;
" $fragmentSpreads": FragmentReference;
}>;

export type KeyTypeData<
Expand Down
Loading