Skip to content

Commit

Permalink
Add support
Browse files Browse the repository at this point in the history
  • Loading branch information
Markionium committed Dec 5, 2023
1 parent 18f9bae commit 25a8cd8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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

0 comments on commit 25a8cd8

Please sign in to comment.