diff --git a/graphql/index.tsx b/graphql/index.tsx index 506f99b9a..794cab955 100644 --- a/graphql/index.tsx +++ b/graphql/index.tsx @@ -356,6 +356,8 @@ export type Query = { challenges: Array exerciseSubmissions: Array exercises: Array + getChildComments: Array + getExerciseComments: Array getLessonMentors?: Maybe>> getPreviousSubmissions?: Maybe> isTokenValid: Scalars['Boolean'] @@ -370,6 +372,14 @@ export type QueryChallengesArgs = { lessonId?: InputMaybe } +export type QueryGetChildCommentsArgs = { + parentId: Scalars['Int'] +} + +export type QueryGetExerciseCommentsArgs = { + exerciseId: Scalars['Int'] +} + export type QueryGetLessonMentorsArgs = { lessonId: Scalars['Int'] } @@ -1412,6 +1422,66 @@ export type AddExerciseCommentMutation = { } } +export type ChildCommentsQueryVariables = Exact<{ + parentId: Scalars['Int'] +}> + +export type ChildCommentsQuery = { + __typename?: 'Query' + getChildComments: Array<{ + __typename?: 'ExerciseComment' + id: number + exerciseId: number + authorId: number + content: string + userPic?: string | null + createdAt: string + updatedAt?: string | null + author: { __typename?: 'User'; username: string } + replies?: Array<{ + __typename?: 'ExerciseComment' + id: number + exerciseId: number + authorId: number + content: string + userPic?: string | null + createdAt: string + updatedAt?: string | null + author: { __typename?: 'User'; username: string } + } | null> | null + }> +} + +export type ExerciseCommentsQueryVariables = Exact<{ + exerciseId: Scalars['Int'] +}> + +export type ExerciseCommentsQuery = { + __typename?: 'Query' + getExerciseComments: Array<{ + __typename?: 'ExerciseComment' + id: number + exerciseId: number + authorId: number + content: string + userPic?: string | null + createdAt: string + updatedAt?: string | null + author: { __typename?: 'User'; username: string } + replies?: Array<{ + __typename?: 'ExerciseComment' + id: number + exerciseId: number + authorId: number + content: string + userPic?: string | null + createdAt: string + updatedAt?: string | null + author: { __typename?: 'User'; username: string } + } | null> | null + }> +} + export type WithIndex = TObject & Record export type ResolversObject = WithIndex @@ -1982,6 +2052,18 @@ export type QueryResolvers< ParentType, ContextType > + getChildComments?: Resolver< + Array, + ParentType, + ContextType, + RequireFields + > + getExerciseComments?: Resolver< + Array, + ParentType, + ContextType, + RequireFields + > getLessonMentors?: Resolver< Maybe>>, ParentType, @@ -6047,6 +6129,226 @@ export type AddExerciseCommentMutationOptions = Apollo.BaseMutationOptions< AddExerciseCommentMutation, AddExerciseCommentMutationVariables > +export const ChildCommentsDocument = gql` + query childComments($parentId: Int!) { + getChildComments(parentId: $parentId) { + id + exerciseId + authorId + content + userPic + createdAt + updatedAt + author { + username + } + replies { + id + exerciseId + authorId + content + userPic + createdAt + updatedAt + author { + username + } + } + } + } +` +export type ChildCommentsProps< + TChildProps = {}, + TDataName extends string = 'data' +> = { + [key in TDataName]: ApolloReactHoc.DataValue< + ChildCommentsQuery, + ChildCommentsQueryVariables + > +} & TChildProps +export function withChildComments< + TProps, + TChildProps = {}, + TDataName extends string = 'data' +>( + operationOptions?: ApolloReactHoc.OperationOption< + TProps, + ChildCommentsQuery, + ChildCommentsQueryVariables, + ChildCommentsProps + > +) { + return ApolloReactHoc.withQuery< + TProps, + ChildCommentsQuery, + ChildCommentsQueryVariables, + ChildCommentsProps + >(ChildCommentsDocument, { + alias: 'childComments', + ...operationOptions + }) +} + +/** + * __useChildCommentsQuery__ + * + * To run a query within a React component, call `useChildCommentsQuery` and pass it any options that fit your needs. + * When your component renders, `useChildCommentsQuery` 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 } = useChildCommentsQuery({ + * variables: { + * parentId: // value for 'parentId' + * }, + * }); + */ +export function useChildCommentsQuery( + baseOptions: Apollo.QueryHookOptions< + ChildCommentsQuery, + ChildCommentsQueryVariables + > +) { + const options = { ...defaultOptions, ...baseOptions } + return Apollo.useQuery( + ChildCommentsDocument, + options + ) +} +export function useChildCommentsLazyQuery( + baseOptions?: Apollo.LazyQueryHookOptions< + ChildCommentsQuery, + ChildCommentsQueryVariables + > +) { + const options = { ...defaultOptions, ...baseOptions } + return Apollo.useLazyQuery( + ChildCommentsDocument, + options + ) +} +export type ChildCommentsQueryHookResult = ReturnType< + typeof useChildCommentsQuery +> +export type ChildCommentsLazyQueryHookResult = ReturnType< + typeof useChildCommentsLazyQuery +> +export type ChildCommentsQueryResult = Apollo.QueryResult< + ChildCommentsQuery, + ChildCommentsQueryVariables +> +export const ExerciseCommentsDocument = gql` + query exerciseComments($exerciseId: Int!) { + getExerciseComments(exerciseId: $exerciseId) { + id + exerciseId + authorId + content + userPic + createdAt + updatedAt + author { + username + } + replies { + id + exerciseId + authorId + content + userPic + createdAt + updatedAt + author { + username + } + } + } + } +` +export type ExerciseCommentsProps< + TChildProps = {}, + TDataName extends string = 'data' +> = { + [key in TDataName]: ApolloReactHoc.DataValue< + ExerciseCommentsQuery, + ExerciseCommentsQueryVariables + > +} & TChildProps +export function withExerciseComments< + TProps, + TChildProps = {}, + TDataName extends string = 'data' +>( + operationOptions?: ApolloReactHoc.OperationOption< + TProps, + ExerciseCommentsQuery, + ExerciseCommentsQueryVariables, + ExerciseCommentsProps + > +) { + return ApolloReactHoc.withQuery< + TProps, + ExerciseCommentsQuery, + ExerciseCommentsQueryVariables, + ExerciseCommentsProps + >(ExerciseCommentsDocument, { + alias: 'exerciseComments', + ...operationOptions + }) +} + +/** + * __useExerciseCommentsQuery__ + * + * To run a query within a React component, call `useExerciseCommentsQuery` and pass it any options that fit your needs. + * When your component renders, `useExerciseCommentsQuery` 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 } = useExerciseCommentsQuery({ + * variables: { + * exerciseId: // value for 'exerciseId' + * }, + * }); + */ +export function useExerciseCommentsQuery( + baseOptions: Apollo.QueryHookOptions< + ExerciseCommentsQuery, + ExerciseCommentsQueryVariables + > +) { + const options = { ...defaultOptions, ...baseOptions } + return Apollo.useQuery( + ExerciseCommentsDocument, + options + ) +} +export function useExerciseCommentsLazyQuery( + baseOptions?: Apollo.LazyQueryHookOptions< + ExerciseCommentsQuery, + ExerciseCommentsQueryVariables + > +) { + const options = { ...defaultOptions, ...baseOptions } + return Apollo.useLazyQuery< + ExerciseCommentsQuery, + ExerciseCommentsQueryVariables + >(ExerciseCommentsDocument, options) +} +export type ExerciseCommentsQueryHookResult = ReturnType< + typeof useExerciseCommentsQuery +> +export type ExerciseCommentsLazyQueryHookResult = ReturnType< + typeof useExerciseCommentsLazyQuery +> +export type ExerciseCommentsQueryResult = Apollo.QueryResult< + ExerciseCommentsQuery, + ExerciseCommentsQueryVariables +> export type AlertKeySpecifier = ( | 'id' | 'text' @@ -6301,6 +6603,8 @@ export type QueryKeySpecifier = ( | 'challenges' | 'exerciseSubmissions' | 'exercises' + | 'getChildComments' + | 'getExerciseComments' | 'getLessonMentors' | 'getPreviousSubmissions' | 'isTokenValid' @@ -6317,6 +6621,8 @@ export type QueryFieldPolicy = { challenges?: FieldPolicy | FieldReadFunction exerciseSubmissions?: FieldPolicy | FieldReadFunction exercises?: FieldPolicy | FieldReadFunction + getChildComments?: FieldPolicy | FieldReadFunction + getExerciseComments?: FieldPolicy | FieldReadFunction getLessonMentors?: FieldPolicy | FieldReadFunction getPreviousSubmissions?: FieldPolicy | FieldReadFunction isTokenValid?: FieldPolicy | FieldReadFunction diff --git a/graphql/queries/getChildComments.ts b/graphql/queries/getChildComments.ts new file mode 100644 index 000000000..7a460f7d1 --- /dev/null +++ b/graphql/queries/getChildComments.ts @@ -0,0 +1,31 @@ +import { gql } from '@apollo/client' + +const CHILD_COMMENTS = gql` + query childComments($parentId: Int!) { + getChildComments(parentId: $parentId) { + id + exerciseId + authorId + content + userPic + createdAt + updatedAt + author { + username + } + replies { + id + exerciseId + authorId + content + userPic + createdAt + updatedAt + author { + username + } + } + } + } +` +export default CHILD_COMMENTS diff --git a/graphql/queries/getExerciseComments.ts b/graphql/queries/getExerciseComments.ts new file mode 100644 index 000000000..1bc1ee101 --- /dev/null +++ b/graphql/queries/getExerciseComments.ts @@ -0,0 +1,31 @@ +import { gql } from '@apollo/client' + +const EXERCISE_COMMENTS = gql` + query exerciseComments($exerciseId: Int!) { + getExerciseComments(exerciseId: $exerciseId) { + id + exerciseId + authorId + content + userPic + createdAt + updatedAt + author { + username + } + replies { + id + exerciseId + authorId + content + userPic + createdAt + updatedAt + author { + username + } + } + } + } +` +export default EXERCISE_COMMENTS diff --git a/graphql/resolvers/exerciseCommentCrud.test.js b/graphql/resolvers/exerciseCommentCrud.test.js index 5d37de105..d58c7f0b5 100644 --- a/graphql/resolvers/exerciseCommentCrud.test.js +++ b/graphql/resolvers/exerciseCommentCrud.test.js @@ -82,7 +82,8 @@ describe('getExerciseComment resolver test', () => { expect(prismaMock.exerciseComment.findMany).toBeCalledWith({ where: { parentId: null, exerciseId: 1 }, include: { - replies: true + replies: true, + author: true } }) }) @@ -119,7 +120,8 @@ describe('getChildComments resolver tests', () => { expect(prismaMock.exerciseComment.findMany).toBeCalledWith({ where: { parentId: 1 }, include: { - replies: true + replies: true, + author: true } }) }) diff --git a/graphql/resolvers/exerciseCommentCrud.ts b/graphql/resolvers/exerciseCommentCrud.ts index 710903bea..bdb5537c2 100644 --- a/graphql/resolvers/exerciseCommentCrud.ts +++ b/graphql/resolvers/exerciseCommentCrud.ts @@ -1,29 +1,33 @@ -import { MutationAddExerciseCommentArgs } from '..' +import { + MutationAddExerciseCommentArgs, + QueryGetExerciseCommentsArgs, + QueryGetChildCommentsArgs +} from '..' import { Context } from '../../@types/helpers' import prisma from '../../prisma' export const getExerciseComments = async ( _parent: void, - _args: { exerciseId: number } + { exerciseId }: QueryGetExerciseCommentsArgs ) => { - const exerciseId = _args.exerciseId return prisma.exerciseComment.findMany({ where: { parentId: null, exerciseId }, include: { - replies: true + replies: true, + author: true } }) } export const getChildComments = async ( _parent: void, - _args: { parentId: number } + { parentId }: QueryGetChildCommentsArgs ) => { - const parentId = _args.parentId return prisma.exerciseComment.findMany({ where: { parentId }, include: { - replies: true + replies: true, + author: true } }) }