From 3624b62548b064b3feaad8161bdbf4b8a8785854 Mon Sep 17 00:00:00 2001 From: Flacial Date: Thu, 1 Jun 2023 12:30:06 +0400 Subject: [PATCH 1/3] refactor: Update submission query fields --- graphql/queries/fragments/submissionsFragment.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/graphql/queries/fragments/submissionsFragment.ts b/graphql/queries/fragments/submissionsFragment.ts index 7726c2171..7bea295c5 100644 --- a/graphql/queries/fragments/submissionsFragment.ts +++ b/graphql/queries/fragments/submissionsFragment.ts @@ -9,6 +9,7 @@ const SUBMISSIONS_INFO = gql` challenge { title description + id } challengeId lessonId From 7d6c8541e16cc87c06fd0dca2d7e1463f4768679 Mon Sep 17 00:00:00 2001 From: Flacial Date: Thu, 1 Jun 2023 12:30:19 +0400 Subject: [PATCH 2/3] Update GraphQL index file --- graphql/index.tsx | 316 ++++++++++++++++++++++++---------------------- 1 file changed, 166 insertions(+), 150 deletions(-) diff --git a/graphql/index.tsx b/graphql/index.tsx index 9dec5afe1..e192f6ccb 100644 --- a/graphql/index.tsx +++ b/graphql/index.tsx @@ -510,57 +510,6 @@ export type UserLesson = { userId?: Maybe } -export type LessonAndChallengeInfoFragment = { - __typename?: 'Lesson' - id: number - docUrl?: string | null - githubUrl?: string | null - videoUrl?: string | null - chatUrl?: string | null - order: number - description: string - title: string - challenges: Array<{ - __typename?: 'Challenge' - id: number - description: string - lessonId: number - title: string - order: number - }> -} - -export type SubmissionsInfoFragment = { - __typename?: 'Submission' - id: number - status: SubmissionStatus - diff?: string | null - comment?: string | null - challengeId: number - lessonId: number - createdAt?: string | null - updatedAt: string - challenge: { __typename?: 'Challenge'; title: string; description: string } - user: { __typename?: 'User'; id: number; username: string } - reviewer?: { - __typename?: 'User' - id: number - username: string - name: string - } | null - comments?: Array<{ - __typename?: 'Comment' - id: number - content: string - submissionId: number - createdAt: string - authorId: number - line?: number | null - fileName?: string | null - author?: { __typename?: 'User'; username: string; name: string } | null - }> | null -} - export type AcceptSubmissionMutationVariables = Exact<{ submissionId: Scalars['Int'] comment: Scalars['String'] @@ -852,6 +801,20 @@ export type EditCommentMutation = { editComment?: { __typename?: 'Comment'; id: number; content: string } | null } +export type EditExerciseCommentMutationVariables = Exact<{ + id: Scalars['Int'] + content: Scalars['String'] +}> + +export type EditExerciseCommentMutation = { + __typename?: 'Mutation' + editExerciseComment: { + __typename?: 'ExerciseComment' + id: number + content: string + } +} + export type FlagExerciseMutationVariables = Exact<{ id: Scalars['Int'] flagReason: Scalars['String'] @@ -862,6 +825,62 @@ export type FlagExerciseMutation = { flagExercise?: { __typename?: 'Exercise'; id: number } | null } +export type LessonAndChallengeInfoFragment = { + __typename?: 'Lesson' + id: number + docUrl?: string | null + githubUrl?: string | null + videoUrl?: string | null + chatUrl?: string | null + order: number + description: string + title: string + challenges: Array<{ + __typename?: 'Challenge' + id: number + description: string + lessonId: number + title: string + order: number + }> +} + +export type SubmissionsInfoFragment = { + __typename?: 'Submission' + id: number + status: SubmissionStatus + diff?: string | null + comment?: string | null + challengeId: number + lessonId: number + createdAt?: string | null + updatedAt: string + challenge: { + __typename?: 'Challenge' + title: string + description: string + id: number + } + user: { __typename?: 'User'; id: number; username: string } + reviewer?: { + __typename?: 'User' + id: number + username: string + name: string + } | null + comments?: Array<{ + __typename?: 'Comment' + id: number + content: string + submissionId: number + createdAt: string + authorId: number + line?: number | null + fileName?: string | null + author?: { __typename?: 'User'; username: string; name: string } | null + }> | null +} + export type GetAppQueryVariables = Exact<{ [key: string]: never }> export type GetAppQuery = { @@ -1124,7 +1143,12 @@ export type GetPreviousSubmissionsQuery = { lessonId: number createdAt?: string | null updatedAt: string - challenge: { __typename?: 'Challenge'; title: string; description: string } + challenge: { + __typename?: 'Challenge' + title: string + description: string + id: number + } user: { __typename?: 'User'; id: number; username: string } reviewer?: { __typename?: 'User' @@ -1203,7 +1227,12 @@ export type SubmissionsQuery = { lessonId: number createdAt?: string | null updatedAt: string - challenge: { __typename?: 'Challenge'; title: string; description: string } + challenge: { + __typename?: 'Challenge' + title: string + description: string + id: number + } user: { __typename?: 'User'; id: number; username: string } reviewer?: { __typename?: 'User' @@ -1549,20 +1578,6 @@ export type UserInfoQuery = { } | null } -export type EditExerciseCommentMutationVariables = Exact<{ - id: Scalars['Int'] - content: Scalars['String'] -}> - -export type EditExerciseCommentMutation = { - __typename?: 'Mutation' - editExerciseComment: { - __typename?: 'ExerciseComment' - id: number - content: string - } -} - export type WithIndex = TObject & Record export type ResolversObject = WithIndex @@ -2386,6 +2401,7 @@ export const SubmissionsInfoFragmentDoc = gql` challenge { title description + id } challengeId lessonId @@ -3955,6 +3971,89 @@ export type EditCommentMutationOptions = Apollo.BaseMutationOptions< EditCommentMutation, EditCommentMutationVariables > +export const EditExerciseCommentDocument = gql` + mutation editExerciseComment($id: Int!, $content: String!) { + editExerciseComment(id: $id, content: $content) { + id + content + } + } +` +export type EditExerciseCommentMutationFn = Apollo.MutationFunction< + EditExerciseCommentMutation, + EditExerciseCommentMutationVariables +> +export type EditExerciseCommentProps< + TChildProps = {}, + TDataName extends string = 'mutate' +> = { + [key in TDataName]: Apollo.MutationFunction< + EditExerciseCommentMutation, + EditExerciseCommentMutationVariables + > +} & TChildProps +export function withEditExerciseComment< + TProps, + TChildProps = {}, + TDataName extends string = 'mutate' +>( + operationOptions?: ApolloReactHoc.OperationOption< + TProps, + EditExerciseCommentMutation, + EditExerciseCommentMutationVariables, + EditExerciseCommentProps + > +) { + return ApolloReactHoc.withMutation< + TProps, + EditExerciseCommentMutation, + EditExerciseCommentMutationVariables, + EditExerciseCommentProps + >(EditExerciseCommentDocument, { + alias: 'editExerciseComment', + ...operationOptions + }) +} + +/** + * __useEditExerciseCommentMutation__ + * + * To run a mutation, you first call `useEditExerciseCommentMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `useEditExerciseCommentMutation` returns a tuple that includes: + * - A mutate function that you can call at any time to execute the mutation + * - An object with fields that represent the current status of the mutation's execution + * + * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; + * + * @example + * const [editExerciseCommentMutation, { data, loading, error }] = useEditExerciseCommentMutation({ + * variables: { + * id: // value for 'id' + * content: // value for 'content' + * }, + * }); + */ +export function useEditExerciseCommentMutation( + baseOptions?: Apollo.MutationHookOptions< + EditExerciseCommentMutation, + EditExerciseCommentMutationVariables + > +) { + const options = { ...defaultOptions, ...baseOptions } + return Apollo.useMutation< + EditExerciseCommentMutation, + EditExerciseCommentMutationVariables + >(EditExerciseCommentDocument, options) +} +export type EditExerciseCommentMutationHookResult = ReturnType< + typeof useEditExerciseCommentMutation +> +export type EditExerciseCommentMutationResult = + Apollo.MutationResult +export type EditExerciseCommentMutationOptions = Apollo.BaseMutationOptions< + EditExerciseCommentMutation, + EditExerciseCommentMutationVariables +> export const FlagExerciseDocument = gql` mutation flagExercise($id: Int!, $flagReason: String!) { flagExercise(id: $id, flagReason: $flagReason) { @@ -6717,89 +6816,6 @@ export type UserInfoQueryResult = Apollo.QueryResult< UserInfoQuery, UserInfoQueryVariables > -export const EditExerciseCommentDocument = gql` - mutation editExerciseComment($id: Int!, $content: String!) { - editExerciseComment(id: $id, content: $content) { - id - content - } - } -` -export type EditExerciseCommentMutationFn = Apollo.MutationFunction< - EditExerciseCommentMutation, - EditExerciseCommentMutationVariables -> -export type EditExerciseCommentProps< - TChildProps = {}, - TDataName extends string = 'mutate' -> = { - [key in TDataName]: Apollo.MutationFunction< - EditExerciseCommentMutation, - EditExerciseCommentMutationVariables - > -} & TChildProps -export function withEditExerciseComment< - TProps, - TChildProps = {}, - TDataName extends string = 'mutate' ->( - operationOptions?: ApolloReactHoc.OperationOption< - TProps, - EditExerciseCommentMutation, - EditExerciseCommentMutationVariables, - EditExerciseCommentProps - > -) { - return ApolloReactHoc.withMutation< - TProps, - EditExerciseCommentMutation, - EditExerciseCommentMutationVariables, - EditExerciseCommentProps - >(EditExerciseCommentDocument, { - alias: 'editExerciseComment', - ...operationOptions - }) -} - -/** - * __useEditExerciseCommentMutation__ - * - * To run a mutation, you first call `useEditExerciseCommentMutation` within a React component and pass it any options that fit your needs. - * When your component renders, `useEditExerciseCommentMutation` returns a tuple that includes: - * - A mutate function that you can call at any time to execute the mutation - * - An object with fields that represent the current status of the mutation's execution - * - * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; - * - * @example - * const [editExerciseCommentMutation, { data, loading, error }] = useEditExerciseCommentMutation({ - * variables: { - * id: // value for 'id' - * content: // value for 'content' - * }, - * }); - */ -export function useEditExerciseCommentMutation( - baseOptions?: Apollo.MutationHookOptions< - EditExerciseCommentMutation, - EditExerciseCommentMutationVariables - > -) { - const options = { ...defaultOptions, ...baseOptions } - return Apollo.useMutation< - EditExerciseCommentMutation, - EditExerciseCommentMutationVariables - >(EditExerciseCommentDocument, options) -} -export type EditExerciseCommentMutationHookResult = ReturnType< - typeof useEditExerciseCommentMutation -> -export type EditExerciseCommentMutationResult = - Apollo.MutationResult -export type EditExerciseCommentMutationOptions = Apollo.BaseMutationOptions< - EditExerciseCommentMutation, - EditExerciseCommentMutationVariables -> export type AlertKeySpecifier = ( | 'id' | 'text' From 06becadc6dddc5c32cffece112cf73beac677cb3 Mon Sep 17 00:00:00 2001 From: Flacial Date: Thu, 1 Jun 2023 12:30:32 +0400 Subject: [PATCH 3/3] test: Update submission query dummy data --- __dummy__/getPreviousSubmissionsData.ts | 9 ++++++--- __dummy__/submission.ts | 3 ++- __tests__/pages/review/[lesson].test.js | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/__dummy__/getPreviousSubmissionsData.ts b/__dummy__/getPreviousSubmissionsData.ts index 73c935013..e920fb004 100644 --- a/__dummy__/getPreviousSubmissionsData.ts +++ b/__dummy__/getPreviousSubmissionsData.ts @@ -15,7 +15,8 @@ const dummyPreviousSubmissionsData: GetPreviousSubmissionsQuery = { __typename: 'Challenge', title: 'Functional 3 Sum', description: - 'Write a function that takes in 2 numbers, return a function that takes in a number that returns the sum of all 3 numbers when called. Example: const a = solution(1,2); // a is a function // a(1) returns 4 because 1+2+1 // a(5) returns 8 because 1 + 2 + 5 // a(2) returns 5 because 1 + 2 + 2' + 'Write a function that takes in 2 numbers, return a function that takes in a number that returns the sum of all 3 numbers when called. Example: const a = solution(1,2); // a is a function // a(1) returns 4 because 1+2+1 // a(5) returns 8 because 1 + 2 + 5 // a(2) returns 5 because 1 + 2 + 2', + id: 1 }, challengeId: 9, lessonId: 1, @@ -39,7 +40,8 @@ const dummyPreviousSubmissionsData: GetPreviousSubmissionsQuery = { __typename: 'Challenge', title: 'Functional 3 Sum', description: - 'Write a function that takes in 2 numbers, return a function that takes in a number that returns the sum of all 3 numbers when called. Example: const a = solution(1,2); // a is a function // a(1) returns 4 because 1+2+1 // a(5) returns 8 because 1 + 2 + 5 // a(2) returns 5 because 1 + 2 + 2' + 'Write a function that takes in 2 numbers, return a function that takes in a number that returns the sum of all 3 numbers when called. Example: const a = solution(1,2); // a is a function // a(1) returns 4 because 1+2+1 // a(5) returns 8 because 1 + 2 + 5 // a(2) returns 5 because 1 + 2 + 2', + id: 1 }, challengeId: 9, lessonId: 1, @@ -63,7 +65,8 @@ const dummyPreviousSubmissionsData: GetPreviousSubmissionsQuery = { __typename: 'Challenge', title: 'Functional 3 Sum', description: - 'Write a function that takes in 2 numbers, return a function that takes in a number that returns the sum of all 3 numbers when called. Example: const a = solution(1,2); // a is a function // a(1) returns 4 because 1+2+1 // a(5) returns 8 because 1 + 2 + 5 // a(2) returns 5 because 1 + 2 + 2' + 'Write a function that takes in 2 numbers, return a function that takes in a number that returns the sum of all 3 numbers when called. Example: const a = solution(1,2); // a is a function // a(1) returns 4 because 1+2+1 // a(5) returns 8 because 1 + 2 + 5 // a(2) returns 5 because 1 + 2 + 2', + id: 1 }, challengeId: 9, lessonId: 1, diff --git a/__dummy__/submission.ts b/__dummy__/submission.ts index 30589a6ce..9d8b126e6 100644 --- a/__dummy__/submission.ts +++ b/__dummy__/submission.ts @@ -9,7 +9,8 @@ const submissionData = { title: 'Is First Num Bigger', description: "Write a function that takes in 2 numbers and returns true if the first number is greater than the second, false otherwise.\n\nHere's how another developer might use your function:\n\n```\nsolution(5,9) // Should return false\nsolution(4,1) // Should return true\n```", - __typename: 'Challenge' + __typename: 'Challenge', + id: 1 }, challengeId: 6, lessonId: 1, diff --git a/__tests__/pages/review/[lesson].test.js b/__tests__/pages/review/[lesson].test.js index 6f7c6c86d..e61ae3be9 100644 --- a/__tests__/pages/review/[lesson].test.js +++ b/__tests__/pages/review/[lesson].test.js @@ -53,7 +53,8 @@ const getSubmissionsMock = { title: 'Sum of 2 Numbers', description: "Write a function that takes in 2 numbers and returns their sum. Here's how another developer might use your function: solution(5,9) // Should return 14 solution(4,1) // Should return 5", - __typename: 'Challenge' + __typename: 'Challenge', + id: 2 }, challengeId: 107, lessonId: 5,