From c6ee137505f434d9f8c3346bc19eb0d0565331af Mon Sep 17 00:00:00 2001 From: Sboonny Date: Wed, 21 Dec 2022 04:31:29 +0000 Subject: [PATCH 1/8] remove extra code --- server/src/controllers/Chapter/resolver.ts | 5 ++++- server/src/controllers/Events/resolver.ts | 2 -- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/server/src/controllers/Chapter/resolver.ts b/server/src/controllers/Chapter/resolver.ts index d56826947f..860c6d7f42 100644 --- a/server/src/controllers/Chapter/resolver.ts +++ b/server/src/controllers/Chapter/resolver.ts @@ -34,13 +34,16 @@ import { CreateChapterInputs, UpdateChapterInputs } from './inputs'; @Resolver() export class ChapterResolver { @Query(() => [ChapterCardRelations]) - async chapters(): Promise { + async chapters( + @Arg('limit', () => Int, { nullable: true }) limit?: number, + ): Promise { return await prisma.chapters.findMany({ include: { events: { where: { AND: [{ canceled: false }, { ends_at: { gt: new Date() } }], }, + take: limit, orderBy: { start_at: 'asc' }, }, chapter_users: { diff --git a/server/src/controllers/Events/resolver.ts b/server/src/controllers/Events/resolver.ts index 79b5593e8b..19ccee68b2 100644 --- a/server/src/controllers/Events/resolver.ts +++ b/server/src/controllers/Events/resolver.ts @@ -352,7 +352,6 @@ export class EventResolver { @Query(() => [EventWithVenue]) async dashboardEvents( @Ctx() ctx: Required, - @Arg('limit', () => Int, { nullable: true }) limit?: number, ): Promise { return await prisma.events.findMany({ where: { @@ -361,7 +360,6 @@ export class EventResolver { }), }, include: { venue: true }, - take: limit, orderBy: { start_at: 'asc' }, }); } From a676310a08a507c90b07e55c440eb05662ba7875 Mon Sep 17 00:00:00 2001 From: Sboonny Date: Wed, 21 Dec 2022 04:39:55 +0000 Subject: [PATCH 2/8] generate apollo api --- client/graphql.schema.json | 30 +++++++++++++++--------------- client/src/generated/graphql.tsx | 8 ++++---- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/client/graphql.schema.json b/client/graphql.schema.json index 1df63c07ef..b3502993b1 100644 --- a/client/graphql.schema.json +++ b/client/graphql.schema.json @@ -5208,7 +5208,20 @@ { "name": "chapters", "description": null, - "args": [], + "args": [ + { + "name": "limit", + "description": null, + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + } + ], "type": { "kind": "NON_NULL", "name": null, @@ -5318,20 +5331,7 @@ { "name": "dashboardEvents", "description": null, - "args": [ - { - "name": "limit", - "description": null, - "type": { - "kind": "SCALAR", - "name": "Int", - "ofType": null - }, - "defaultValue": null, - "isDeprecated": false, - "deprecationReason": null - } - ], + "args": [], "type": { "kind": "NON_NULL", "name": null, diff --git a/client/src/generated/graphql.tsx b/client/src/generated/graphql.tsx index 3f56ec377b..e08f5f1531 100644 --- a/client/src/generated/graphql.tsx +++ b/client/src/generated/graphql.tsx @@ -568,6 +568,10 @@ export type QueryChapterVenuesArgs = { chapterId: Scalars['Int']; }; +export type QueryChaptersArgs = { + limit?: InputMaybe; +}; + export type QueryDashboardChapterArgs = { id: Scalars['Int']; }; @@ -576,10 +580,6 @@ export type QueryDashboardEventArgs = { id: Scalars['Int']; }; -export type QueryDashboardEventsArgs = { - limit?: InputMaybe; -}; - export type QueryDashboardSponsorArgs = { id: Scalars['Int']; }; From 52ecc37b8d7593af3350a438076cc68c50a74a35 Mon Sep 17 00:00:00 2001 From: Sboonny Date: Wed, 21 Dec 2022 13:14:50 +0000 Subject: [PATCH 3/8] graphql slicing doesn't work in queires --- client/src/modules/chapters/graphql/queries.ts | 3 ++- client/src/modules/home/graphql/queries.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/client/src/modules/chapters/graphql/queries.ts b/client/src/modules/chapters/graphql/queries.ts index 09335ad270..f2cf465ffb 100644 --- a/client/src/modules/chapters/graphql/queries.ts +++ b/client/src/modules/chapters/graphql/queries.ts @@ -43,6 +43,7 @@ export const CHAPTER_USER = gql` } `; +// https://graphql.org/learn/pagination/#slicing export const CHAPTERS = gql` query chapters { chapters { @@ -51,7 +52,7 @@ export const CHAPTERS = gql` description logo_url banner_url - events { + events(first: 2) { id canceled start_at diff --git a/client/src/modules/home/graphql/queries.ts b/client/src/modules/home/graphql/queries.ts index d6c30d0135..412f26d744 100644 --- a/client/src/modules/home/graphql/queries.ts +++ b/client/src/modules/home/graphql/queries.ts @@ -23,7 +23,7 @@ export const HOME_PAGE_QUERY = gql` description banner_url logo_url - events { + events(first: 2) { id canceled start_at From 58ee2bfd2e510fa94f6f06de0098650f6bb88a67 Mon Sep 17 00:00:00 2001 From: Sboonny Date: Wed, 21 Dec 2022 13:37:20 +0000 Subject: [PATCH 4/8] clean the queries --- client/src/modules/chapters/graphql/queries.ts | 3 +-- client/src/modules/home/graphql/queries.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/client/src/modules/chapters/graphql/queries.ts b/client/src/modules/chapters/graphql/queries.ts index f2cf465ffb..09335ad270 100644 --- a/client/src/modules/chapters/graphql/queries.ts +++ b/client/src/modules/chapters/graphql/queries.ts @@ -43,7 +43,6 @@ export const CHAPTER_USER = gql` } `; -// https://graphql.org/learn/pagination/#slicing export const CHAPTERS = gql` query chapters { chapters { @@ -52,7 +51,7 @@ export const CHAPTERS = gql` description logo_url banner_url - events(first: 2) { + events { id canceled start_at diff --git a/client/src/modules/home/graphql/queries.ts b/client/src/modules/home/graphql/queries.ts index 412f26d744..d6c30d0135 100644 --- a/client/src/modules/home/graphql/queries.ts +++ b/client/src/modules/home/graphql/queries.ts @@ -23,7 +23,7 @@ export const HOME_PAGE_QUERY = gql` description banner_url logo_url - events(first: 2) { + events { id canceled start_at From 93281df5a08c7c29fd266ed8a60e40ff2373ee7c Mon Sep 17 00:00:00 2001 From: Sboonny Date: Wed, 21 Dec 2022 14:00:59 +0000 Subject: [PATCH 5/8] can't generate apollo api that accept paginating the events --- client/src/generated/graphql.tsx | 269 ------------------ .../src/modules/chapters/graphql/queries.ts | 4 +- .../modules/chapters/pages/chaptersPage.tsx | 4 +- client/src/modules/home/graphql/queries.ts | 2 +- 4 files changed, 6 insertions(+), 273 deletions(-) diff --git a/client/src/generated/graphql.tsx b/client/src/generated/graphql.tsx index e08f5f1531..e68fd9d3b1 100644 --- a/client/src/generated/graphql.tsx +++ b/client/src/generated/graphql.tsx @@ -930,75 +930,6 @@ export type ToggleChapterSubscriptionMutation = { }; }; -export type ChapterQueryVariables = Exact<{ - chapterId: Scalars['Int']; -}>; - -export type ChapterQuery = { - __typename?: 'Query'; - chapter: { - __typename?: 'ChapterWithRelations'; - id: number; - name: string; - description: string; - category: string; - city: string; - region: string; - country: string; - logo_url?: string | null; - banner_url?: string | null; - chat_url?: string | null; - events: Array<{ - __typename?: 'Event'; - id: number; - name: string; - description: string; - start_at: any; - ends_at: any; - invite_only: boolean; - canceled: boolean; - image_url: string; - }>; - }; -}; - -export type ChapterUserQueryVariables = Exact<{ - chapterId: Scalars['Int']; -}>; - -export type ChapterUserQuery = { - __typename?: 'Query'; - chapterUser?: { - __typename?: 'ChapterUserWithRelations'; - subscribed: boolean; - user: { __typename?: 'User'; name: string }; - chapter_role: { __typename?: 'ChapterRole'; name: string }; - } | null; -}; - -export type ChaptersQueryVariables = Exact<{ [key: string]: never }>; - -export type ChaptersQuery = { - __typename?: 'Query'; - chapters: Array<{ - __typename?: 'ChapterCardRelations'; - id: number; - name: string; - description: string; - logo_url?: string | null; - banner_url?: string | null; - events: Array<{ - __typename?: 'Event'; - id: number; - canceled: boolean; - start_at: any; - ends_at: any; - name: string; - }>; - chapter_users: Array<{ __typename?: 'ChapterUser'; subscribed: boolean }>; - }>; -}; - export type CalendarIntegrationStatusQueryVariables = Exact<{ [key: string]: never; }>; @@ -2231,206 +2162,6 @@ export type ToggleChapterSubscriptionMutationOptions = ToggleChapterSubscriptionMutation, ToggleChapterSubscriptionMutationVariables >; -export const ChapterDocument = gql` - query chapter($chapterId: Int!) { - chapter(id: $chapterId) { - id - name - description - category - city - region - country - logo_url - banner_url - chat_url - events { - id - name - description - start_at - ends_at - invite_only - canceled - image_url - invite_only - canceled - } - } - } -`; - -/** - * __useChapterQuery__ - * - * To run a query within a React component, call `useChapterQuery` and pass it any options that fit your needs. - * When your component renders, `useChapterQuery` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useChapterQuery({ - * variables: { - * chapterId: // value for 'chapterId' - * }, - * }); - */ -export function useChapterQuery( - baseOptions: Apollo.QueryHookOptions, -) { - const options = { ...defaultOptions, ...baseOptions }; - return Apollo.useQuery( - ChapterDocument, - options, - ); -} -export function useChapterLazyQuery( - baseOptions?: Apollo.LazyQueryHookOptions< - ChapterQuery, - ChapterQueryVariables - >, -) { - const options = { ...defaultOptions, ...baseOptions }; - return Apollo.useLazyQuery( - ChapterDocument, - options, - ); -} -export type ChapterQueryHookResult = ReturnType; -export type ChapterLazyQueryHookResult = ReturnType; -export type ChapterQueryResult = Apollo.QueryResult< - ChapterQuery, - ChapterQueryVariables ->; -export const ChapterUserDocument = gql` - query chapterUser($chapterId: Int!) { - chapterUser(chapterId: $chapterId) { - user { - name - } - chapter_role { - name - } - subscribed - } - } -`; - -/** - * __useChapterUserQuery__ - * - * To run a query within a React component, call `useChapterUserQuery` and pass it any options that fit your needs. - * When your component renders, `useChapterUserQuery` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useChapterUserQuery({ - * variables: { - * chapterId: // value for 'chapterId' - * }, - * }); - */ -export function useChapterUserQuery( - baseOptions: Apollo.QueryHookOptions< - ChapterUserQuery, - ChapterUserQueryVariables - >, -) { - const options = { ...defaultOptions, ...baseOptions }; - return Apollo.useQuery( - ChapterUserDocument, - options, - ); -} -export function useChapterUserLazyQuery( - baseOptions?: Apollo.LazyQueryHookOptions< - ChapterUserQuery, - ChapterUserQueryVariables - >, -) { - const options = { ...defaultOptions, ...baseOptions }; - return Apollo.useLazyQuery( - ChapterUserDocument, - options, - ); -} -export type ChapterUserQueryHookResult = ReturnType; -export type ChapterUserLazyQueryHookResult = ReturnType< - typeof useChapterUserLazyQuery ->; -export type ChapterUserQueryResult = Apollo.QueryResult< - ChapterUserQuery, - ChapterUserQueryVariables ->; -export const ChaptersDocument = gql` - query chapters { - chapters { - id - name - description - logo_url - banner_url - events { - id - canceled - start_at - ends_at - name - } - chapter_users { - subscribed - } - } - } -`; - -/** - * __useChaptersQuery__ - * - * To run a query within a React component, call `useChaptersQuery` and pass it any options that fit your needs. - * When your component renders, `useChaptersQuery` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useChaptersQuery({ - * variables: { - * }, - * }); - */ -export function useChaptersQuery( - baseOptions?: Apollo.QueryHookOptions, -) { - const options = { ...defaultOptions, ...baseOptions }; - return Apollo.useQuery( - ChaptersDocument, - options, - ); -} -export function useChaptersLazyQuery( - baseOptions?: Apollo.LazyQueryHookOptions< - ChaptersQuery, - ChaptersQueryVariables - >, -) { - const options = { ...defaultOptions, ...baseOptions }; - return Apollo.useLazyQuery( - ChaptersDocument, - options, - ); -} -export type ChaptersQueryHookResult = ReturnType; -export type ChaptersLazyQueryHookResult = ReturnType< - typeof useChaptersLazyQuery ->; -export type ChaptersQueryResult = Apollo.QueryResult< - ChaptersQuery, - ChaptersQueryVariables ->; export const CalendarIntegrationStatusDocument = gql` query calendarIntegrationStatus { calendarIntegrationStatus diff --git a/client/src/modules/chapters/graphql/queries.ts b/client/src/modules/chapters/graphql/queries.ts index 09335ad270..a590babe0b 100644 --- a/client/src/modules/chapters/graphql/queries.ts +++ b/client/src/modules/chapters/graphql/queries.ts @@ -44,14 +44,14 @@ export const CHAPTER_USER = gql` `; export const CHAPTERS = gql` - query chapters { + query chapters($limit: Int) { chapters { id name description logo_url banner_url - events { + events(limit: $limit) { id canceled start_at diff --git a/client/src/modules/chapters/pages/chaptersPage.tsx b/client/src/modules/chapters/pages/chaptersPage.tsx index 93ad6677a8..c0555a2060 100644 --- a/client/src/modules/chapters/pages/chaptersPage.tsx +++ b/client/src/modules/chapters/pages/chaptersPage.tsx @@ -10,7 +10,9 @@ import { checkPermission } from '../../../util/check-permission'; import { Permission } from '../../../../../common/permissions'; export const ChaptersPage: NextPage = () => { - const { loading, error, data } = useChaptersQuery(); + const { loading, error, data } = useChaptersQuery({ + variables: { events: { limit: 3 } }, + }); const { user } = useAuth(); const isLoading = loading || !data; if (isLoading || error) return ; diff --git a/client/src/modules/home/graphql/queries.ts b/client/src/modules/home/graphql/queries.ts index d6c30d0135..6f655d118c 100644 --- a/client/src/modules/home/graphql/queries.ts +++ b/client/src/modules/home/graphql/queries.ts @@ -23,7 +23,7 @@ export const HOME_PAGE_QUERY = gql` description banner_url logo_url - events { + events(limit: $limit) { id canceled start_at From b255717c4bfc4fbe46732f41f2c1e3b9cef82098 Mon Sep 17 00:00:00 2001 From: Sboonny Date: Wed, 4 Jan 2023 09:30:46 +0000 Subject: [PATCH 6/8] limit the number to three events --- client/src/generated/graphql.tsx | 272 ++++++++++++++++++ .../src/modules/chapters/graphql/queries.ts | 4 +- .../modules/chapters/pages/chaptersPage.tsx | 4 +- client/src/modules/home/graphql/queries.ts | 2 +- server/src/controllers/Chapter/resolver.ts | 2 +- 5 files changed, 277 insertions(+), 7 deletions(-) diff --git a/client/src/generated/graphql.tsx b/client/src/generated/graphql.tsx index e68fd9d3b1..b90fb30f79 100644 --- a/client/src/generated/graphql.tsx +++ b/client/src/generated/graphql.tsx @@ -930,6 +930,77 @@ export type ToggleChapterSubscriptionMutation = { }; }; +export type ChapterQueryVariables = Exact<{ + chapterId: Scalars['Int']; +}>; + +export type ChapterQuery = { + __typename?: 'Query'; + chapter: { + __typename?: 'ChapterWithRelations'; + id: number; + name: string; + description: string; + category: string; + city: string; + region: string; + country: string; + logo_url?: string | null; + banner_url?: string | null; + chat_url?: string | null; + events: Array<{ + __typename?: 'Event'; + id: number; + name: string; + description: string; + start_at: any; + ends_at: any; + invite_only: boolean; + canceled: boolean; + image_url: string; + }>; + }; +}; + +export type ChapterUserQueryVariables = Exact<{ + chapterId: Scalars['Int']; +}>; + +export type ChapterUserQuery = { + __typename?: 'Query'; + chapterUser?: { + __typename?: 'ChapterUserWithRelations'; + subscribed: boolean; + user: { __typename?: 'User'; name: string }; + chapter_role: { __typename?: 'ChapterRole'; name: string }; + } | null; +}; + +export type ChaptersQueryVariables = Exact<{ + limit?: InputMaybe; +}>; + +export type ChaptersQuery = { + __typename?: 'Query'; + chapters: Array<{ + __typename?: 'ChapterCardRelations'; + id: number; + name: string; + description: string; + logo_url?: string | null; + banner_url?: string | null; + events: Array<{ + __typename?: 'Event'; + id: number; + canceled: boolean; + start_at: any; + ends_at: any; + name: string; + }>; + chapter_users: Array<{ __typename?: 'ChapterUser'; subscribed: boolean }>; + }>; +}; + export type CalendarIntegrationStatusQueryVariables = Exact<{ [key: string]: never; }>; @@ -2162,6 +2233,207 @@ export type ToggleChapterSubscriptionMutationOptions = ToggleChapterSubscriptionMutation, ToggleChapterSubscriptionMutationVariables >; +export const ChapterDocument = gql` + query chapter($chapterId: Int!) { + chapter(id: $chapterId) { + id + name + description + category + city + region + country + logo_url + banner_url + chat_url + events { + id + name + description + start_at + ends_at + invite_only + canceled + image_url + invite_only + canceled + } + } + } +`; + +/** + * __useChapterQuery__ + * + * To run a query within a React component, call `useChapterQuery` and pass it any options that fit your needs. + * When your component renders, `useChapterQuery` returns an object from Apollo Client that contains loading, error, and data properties + * you can use to render your UI. + * + * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; + * + * @example + * const { data, loading, error } = useChapterQuery({ + * variables: { + * chapterId: // value for 'chapterId' + * }, + * }); + */ +export function useChapterQuery( + baseOptions: Apollo.QueryHookOptions, +) { + const options = { ...defaultOptions, ...baseOptions }; + return Apollo.useQuery( + ChapterDocument, + options, + ); +} +export function useChapterLazyQuery( + baseOptions?: Apollo.LazyQueryHookOptions< + ChapterQuery, + ChapterQueryVariables + >, +) { + const options = { ...defaultOptions, ...baseOptions }; + return Apollo.useLazyQuery( + ChapterDocument, + options, + ); +} +export type ChapterQueryHookResult = ReturnType; +export type ChapterLazyQueryHookResult = ReturnType; +export type ChapterQueryResult = Apollo.QueryResult< + ChapterQuery, + ChapterQueryVariables +>; +export const ChapterUserDocument = gql` + query chapterUser($chapterId: Int!) { + chapterUser(chapterId: $chapterId) { + user { + name + } + chapter_role { + name + } + subscribed + } + } +`; + +/** + * __useChapterUserQuery__ + * + * To run a query within a React component, call `useChapterUserQuery` and pass it any options that fit your needs. + * When your component renders, `useChapterUserQuery` returns an object from Apollo Client that contains loading, error, and data properties + * you can use to render your UI. + * + * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; + * + * @example + * const { data, loading, error } = useChapterUserQuery({ + * variables: { + * chapterId: // value for 'chapterId' + * }, + * }); + */ +export function useChapterUserQuery( + baseOptions: Apollo.QueryHookOptions< + ChapterUserQuery, + ChapterUserQueryVariables + >, +) { + const options = { ...defaultOptions, ...baseOptions }; + return Apollo.useQuery( + ChapterUserDocument, + options, + ); +} +export function useChapterUserLazyQuery( + baseOptions?: Apollo.LazyQueryHookOptions< + ChapterUserQuery, + ChapterUserQueryVariables + >, +) { + const options = { ...defaultOptions, ...baseOptions }; + return Apollo.useLazyQuery( + ChapterUserDocument, + options, + ); +} +export type ChapterUserQueryHookResult = ReturnType; +export type ChapterUserLazyQueryHookResult = ReturnType< + typeof useChapterUserLazyQuery +>; +export type ChapterUserQueryResult = Apollo.QueryResult< + ChapterUserQuery, + ChapterUserQueryVariables +>; +export const ChaptersDocument = gql` + query chapters($limit: Int) { + chapters(limit: $limit) { + id + name + description + logo_url + banner_url + events { + id + canceled + start_at + ends_at + name + } + chapter_users { + subscribed + } + } + } +`; + +/** + * __useChaptersQuery__ + * + * To run a query within a React component, call `useChaptersQuery` and pass it any options that fit your needs. + * When your component renders, `useChaptersQuery` returns an object from Apollo Client that contains loading, error, and data properties + * you can use to render your UI. + * + * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; + * + * @example + * const { data, loading, error } = useChaptersQuery({ + * variables: { + * limit: // value for 'limit' + * }, + * }); + */ +export function useChaptersQuery( + baseOptions?: Apollo.QueryHookOptions, +) { + const options = { ...defaultOptions, ...baseOptions }; + return Apollo.useQuery( + ChaptersDocument, + options, + ); +} +export function useChaptersLazyQuery( + baseOptions?: Apollo.LazyQueryHookOptions< + ChaptersQuery, + ChaptersQueryVariables + >, +) { + const options = { ...defaultOptions, ...baseOptions }; + return Apollo.useLazyQuery( + ChaptersDocument, + options, + ); +} +export type ChaptersQueryHookResult = ReturnType; +export type ChaptersLazyQueryHookResult = ReturnType< + typeof useChaptersLazyQuery +>; +export type ChaptersQueryResult = Apollo.QueryResult< + ChaptersQuery, + ChaptersQueryVariables +>; export const CalendarIntegrationStatusDocument = gql` query calendarIntegrationStatus { calendarIntegrationStatus diff --git a/client/src/modules/chapters/graphql/queries.ts b/client/src/modules/chapters/graphql/queries.ts index a590babe0b..c4454b8b51 100644 --- a/client/src/modules/chapters/graphql/queries.ts +++ b/client/src/modules/chapters/graphql/queries.ts @@ -45,13 +45,13 @@ export const CHAPTER_USER = gql` export const CHAPTERS = gql` query chapters($limit: Int) { - chapters { + chapters(limit: $limit) { id name description logo_url banner_url - events(limit: $limit) { + events { id canceled start_at diff --git a/client/src/modules/chapters/pages/chaptersPage.tsx b/client/src/modules/chapters/pages/chaptersPage.tsx index c0555a2060..93ad6677a8 100644 --- a/client/src/modules/chapters/pages/chaptersPage.tsx +++ b/client/src/modules/chapters/pages/chaptersPage.tsx @@ -10,9 +10,7 @@ import { checkPermission } from '../../../util/check-permission'; import { Permission } from '../../../../../common/permissions'; export const ChaptersPage: NextPage = () => { - const { loading, error, data } = useChaptersQuery({ - variables: { events: { limit: 3 } }, - }); + const { loading, error, data } = useChaptersQuery(); const { user } = useAuth(); const isLoading = loading || !data; if (isLoading || error) return ; diff --git a/client/src/modules/home/graphql/queries.ts b/client/src/modules/home/graphql/queries.ts index 6f655d118c..d6c30d0135 100644 --- a/client/src/modules/home/graphql/queries.ts +++ b/client/src/modules/home/graphql/queries.ts @@ -23,7 +23,7 @@ export const HOME_PAGE_QUERY = gql` description banner_url logo_url - events(limit: $limit) { + events { id canceled start_at diff --git a/server/src/controllers/Chapter/resolver.ts b/server/src/controllers/Chapter/resolver.ts index 860c6d7f42..9d354fb39f 100644 --- a/server/src/controllers/Chapter/resolver.ts +++ b/server/src/controllers/Chapter/resolver.ts @@ -43,7 +43,7 @@ export class ChapterResolver { where: { AND: [{ canceled: false }, { ends_at: { gt: new Date() } }], }, - take: limit, + take: limit ?? 3, orderBy: { start_at: 'asc' }, }, chapter_users: { From f1c5b8c347a851ca487b688f7a1538f1f80ff3f9 Mon Sep 17 00:00:00 2001 From: Sboonny Date: Wed, 4 Jan 2023 09:34:00 +0000 Subject: [PATCH 7/8] remove from the queries --- client/graphql.schema.json | 15 +-------------- client/src/generated/graphql.tsx | 13 +++---------- client/src/modules/chapters/graphql/queries.ts | 4 ++-- server/src/controllers/Chapter/resolver.ts | 6 ++---- 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/client/graphql.schema.json b/client/graphql.schema.json index b3502993b1..33b26a1ece 100644 --- a/client/graphql.schema.json +++ b/client/graphql.schema.json @@ -5208,20 +5208,7 @@ { "name": "chapters", "description": null, - "args": [ - { - "name": "limit", - "description": null, - "type": { - "kind": "SCALAR", - "name": "Int", - "ofType": null - }, - "defaultValue": null, - "isDeprecated": false, - "deprecationReason": null - } - ], + "args": [], "type": { "kind": "NON_NULL", "name": null, diff --git a/client/src/generated/graphql.tsx b/client/src/generated/graphql.tsx index b90fb30f79..9063d0254a 100644 --- a/client/src/generated/graphql.tsx +++ b/client/src/generated/graphql.tsx @@ -568,10 +568,6 @@ export type QueryChapterVenuesArgs = { chapterId: Scalars['Int']; }; -export type QueryChaptersArgs = { - limit?: InputMaybe; -}; - export type QueryDashboardChapterArgs = { id: Scalars['Int']; }; @@ -976,9 +972,7 @@ export type ChapterUserQuery = { } | null; }; -export type ChaptersQueryVariables = Exact<{ - limit?: InputMaybe; -}>; +export type ChaptersQueryVariables = Exact<{ [key: string]: never }>; export type ChaptersQuery = { __typename?: 'Query'; @@ -2368,8 +2362,8 @@ export type ChapterUserQueryResult = Apollo.QueryResult< ChapterUserQueryVariables >; export const ChaptersDocument = gql` - query chapters($limit: Int) { - chapters(limit: $limit) { + query chapters { + chapters { id name description @@ -2401,7 +2395,6 @@ export const ChaptersDocument = gql` * @example * const { data, loading, error } = useChaptersQuery({ * variables: { - * limit: // value for 'limit' * }, * }); */ diff --git a/client/src/modules/chapters/graphql/queries.ts b/client/src/modules/chapters/graphql/queries.ts index c4454b8b51..09335ad270 100644 --- a/client/src/modules/chapters/graphql/queries.ts +++ b/client/src/modules/chapters/graphql/queries.ts @@ -44,8 +44,8 @@ export const CHAPTER_USER = gql` `; export const CHAPTERS = gql` - query chapters($limit: Int) { - chapters(limit: $limit) { + query chapters { + chapters { id name description diff --git a/server/src/controllers/Chapter/resolver.ts b/server/src/controllers/Chapter/resolver.ts index 9d354fb39f..8ec13ac5d1 100644 --- a/server/src/controllers/Chapter/resolver.ts +++ b/server/src/controllers/Chapter/resolver.ts @@ -34,16 +34,14 @@ import { CreateChapterInputs, UpdateChapterInputs } from './inputs'; @Resolver() export class ChapterResolver { @Query(() => [ChapterCardRelations]) - async chapters( - @Arg('limit', () => Int, { nullable: true }) limit?: number, - ): Promise { + async chapters(): Promise { return await prisma.chapters.findMany({ include: { events: { where: { AND: [{ canceled: false }, { ends_at: { gt: new Date() } }], }, - take: limit ?? 3, + take: 3, orderBy: { start_at: 'asc' }, }, chapter_users: { From 5860ac029f0c6e578c9209d5cfec891bbcb29d71 Mon Sep 17 00:00:00 2001 From: Sboonny Date: Wed, 4 Jan 2023 11:52:25 +0000 Subject: [PATCH 8/8] fix chapter card text and order Co-authored-by: gikf <60067306+gikf@users.noreply.github.com> Co-authored-by: Oliver Eyton-Williams --- client/src/components/ChapterCard.tsx | 2 +- server/src/controllers/Chapter/resolver.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/components/ChapterCard.tsx b/client/src/components/ChapterCard.tsx index 7a67284359..b5fa8f105d 100644 --- a/client/src/components/ChapterCard.tsx +++ b/client/src/components/ChapterCard.tsx @@ -96,7 +96,7 @@ export const ChapterCard: React.FC = ({ chapter }) => { marginBlockStart={'.5em'} gridArea="eventheader" > - New Events + Next Events {chapter.events.map(({ id, name, start_at }) => ( diff --git a/server/src/controllers/Chapter/resolver.ts b/server/src/controllers/Chapter/resolver.ts index 8ec13ac5d1..70f8f6af9a 100644 --- a/server/src/controllers/Chapter/resolver.ts +++ b/server/src/controllers/Chapter/resolver.ts @@ -42,7 +42,7 @@ export class ChapterResolver { AND: [{ canceled: false }, { ends_at: { gt: new Date() } }], }, take: 3, - orderBy: { start_at: 'asc' }, + orderBy: { start_at: 'desc' }, }, chapter_users: { include: {