diff --git a/packages/nova-react/src/graphql/hooks.test.tsx b/packages/nova-react/src/graphql/hooks.test.tsx index e9f6e8a..031d07a 100644 --- a/packages/nova-react/src/graphql/hooks.test.tsx +++ b/packages/nova-react/src/graphql/hooks.test.tsx @@ -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, () => { diff --git a/packages/nova-react/src/graphql/types.ts b/packages/nova-react/src/graphql/types.ts index 5893dd4..c35e2d8 100644 --- a/packages/nova-react/src/graphql/types.ts +++ b/packages/nova-react/src/graphql/types.ts @@ -21,8 +21,10 @@ export interface _RefType { " $refType": Ref; } -export interface _FragmentRefs { +export type _FragmentRefs = { " $fragmentRefs": FragmentRefs; +} | { + " $fragmentSpreads": FragmentRefs; } // This is used in the actual artifacts to define the various fragment references a container holds. @@ -44,6 +46,9 @@ export type FragmentReference = unknown; export type KeyType = Readonly<{ " $data"?: TData; " $fragmentRefs": FragmentReference; +}> | Readonly<{ + " $data"?: TData; + " $fragmentSpreads": FragmentReference; }>; export type KeyTypeData<