diff --git a/packages/portal/src/config/refine/graphql/data.ts b/packages/portal/src/config/refine/graphql/data.ts index f547156b..9d5d315e 100644 --- a/packages/portal/src/config/refine/graphql/data.ts +++ b/packages/portal/src/config/refine/graphql/data.ts @@ -228,14 +228,22 @@ export const dataProvider: Required = { if (meta?.gqlQuery) { query = meta.gqlQuery; } else if (meta?.gqlFragment) { - const fragmentDefinition = (meta.gqlFragment as Partial) - .definitions?.[0]; - if (fragmentDefinition?.kind === Kind.FRAGMENT_DEFINITION) { + const gqlDefinitions = + (meta.gqlFragment as Partial).definitions ?? []; + const fragmentDefinition = gqlDefinitions.find( + (def) => def.kind === Kind.FRAGMENT_DEFINITION + ); + if (fragmentDefinition) { const pascalResource = camelcase(singular(resource), { pascalCase: true, }); - query = makeListDocument(pascalResource, resource, fragmentDefinition); + query = makeListDocument( + pascalResource, + resource, + fragmentDefinition.name.value, + gqlDefinitions + ); } } diff --git a/packages/portal/src/config/refine/graphql/makeListDocument.ts b/packages/portal/src/config/refine/graphql/makeListDocument.ts index e8a0e601..66d69c3a 100644 --- a/packages/portal/src/config/refine/graphql/makeListDocument.ts +++ b/packages/portal/src/config/refine/graphql/makeListDocument.ts @@ -4,7 +4,7 @@ import type { AbstractSortItem, } from "@ukdanceblue/common"; import type { ResultOf, TadaDocumentNode } from "gql.tada"; -import type { FragmentDefinitionNode } from "graphql"; +import type { DefinitionNode } from "graphql"; import { Kind, OperationTypeNode } from "graphql"; import pluralize from "pluralize"; @@ -13,7 +13,8 @@ import { PaginationFragment } from "#documents/shared.ts"; export function makeListDocument( pascalResource: string, resource: string, - fragmentDefinition: FragmentDefinitionNode + fragmentName: string, + definitions: readonly DefinitionNode[] ): TadaDocumentNode< { data: unknown; @@ -170,7 +171,7 @@ export function makeListDocument( kind: Kind.FRAGMENT_SPREAD, name: { kind: Kind.NAME, - value: fragmentDefinition.name.value, + value: fragmentName, }, }, ], @@ -182,7 +183,7 @@ export function makeListDocument( ], }, }, - fragmentDefinition, + ...definitions, ...PaginationFragment.definitions, ], }; diff --git a/packages/portal/src/config/refine/resources.tsx b/packages/portal/src/config/refine/resources.tsx index f05cfbfd..524decbe 100644 --- a/packages/portal/src/config/refine/resources.tsx +++ b/packages/portal/src/config/refine/resources.tsx @@ -78,7 +78,7 @@ export const refineResources = [ list: "/fundraising/dbfunds", }, { - name: "fundraising", + name: "fundraisingEntry", meta: { label: "Entries", modelName: "FundraisingEntryNode", diff --git a/packages/portal/src/elements/tables/fundraising/FundraisingEntriesTable.tsx b/packages/portal/src/elements/tables/fundraising/FundraisingEntriesTable.tsx index 8aaf6596..8e5c6bde 100644 --- a/packages/portal/src/elements/tables/fundraising/FundraisingEntriesTable.tsx +++ b/packages/portal/src/elements/tables/fundraising/FundraisingEntriesTable.tsx @@ -61,7 +61,7 @@ export function FundraisingEntriesTable>({ } = useTypedTable({ fragment: FundraisingEntryTableFragment, props: { - resource: "fundraising", + resource: "fundraisingEntry", sorters: { initial: [ { diff --git a/packages/portal/src/routes/teams/$teamId/_layout/fundraising.tsx b/packages/portal/src/routes/teams/$teamId/_layout/fundraising.tsx index c1e92474..5cb6e263 100644 --- a/packages/portal/src/routes/teams/$teamId/_layout/fundraising.tsx +++ b/packages/portal/src/routes/teams/$teamId/_layout/fundraising.tsx @@ -141,7 +141,7 @@ function ViewTeamFundraising() { const { data } = useTypedOne({ fragment: TeamFundraisingFragment, props: { - resource: "fundraising", + resource: "fundraisingEntry", id: useParams({ from: "/teams/$teamId/_layout/fundraising" }).teamId, }, });