Skip to content

Commit

Permalink
Merge pull request #2190 from flacial/2175-create-addexercise-hook
Browse files Browse the repository at this point in the history
feat: Create addExercise hook
  • Loading branch information
flacial authored Aug 20, 2022
2 parents 14b9a56 + bdd1a11 commit 0dcb658
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 0 deletions.
119 changes: 119 additions & 0 deletions graphql/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,25 @@ export type AddCommentMutation = {
addComment?: { __typename?: 'Comment'; id: number } | null
}

export type AddExerciseMutationVariables = Exact<{
moduleId: Scalars['Int']
description: Scalars['String']
answer: Scalars['String']
testStr?: InputMaybe<Scalars['String']>
explanation?: InputMaybe<Scalars['String']>
}>

export type AddExerciseMutation = {
__typename?: 'Mutation'
addExercise: {
__typename?: 'Exercise'
id: number
description: string
answer: string
explanation?: string | null
}
}

export type AddModuleMutationVariables = Exact<{
content: Scalars['String']
lessonId: Scalars['Int']
Expand Down Expand Up @@ -2201,6 +2220,106 @@ export type AddCommentMutationOptions = Apollo.BaseMutationOptions<
AddCommentMutation,
AddCommentMutationVariables
>
export const AddExerciseDocument = gql`
mutation addExercise(
$moduleId: Int!
$description: String!
$answer: String!
$testStr: String
$explanation: String
) {
addExercise(
moduleId: $moduleId
description: $description
answer: $answer
testStr: $testStr
explanation: $explanation
) {
id
description
answer
explanation
}
}
`
export type AddExerciseMutationFn = Apollo.MutationFunction<
AddExerciseMutation,
AddExerciseMutationVariables
>
export type AddExerciseProps<
TChildProps = {},
TDataName extends string = 'mutate'
> = {
[key in TDataName]: Apollo.MutationFunction<
AddExerciseMutation,
AddExerciseMutationVariables
>
} & TChildProps
export function withAddExercise<
TProps,
TChildProps = {},
TDataName extends string = 'mutate'
>(
operationOptions?: ApolloReactHoc.OperationOption<
TProps,
AddExerciseMutation,
AddExerciseMutationVariables,
AddExerciseProps<TChildProps, TDataName>
>
) {
return ApolloReactHoc.withMutation<
TProps,
AddExerciseMutation,
AddExerciseMutationVariables,
AddExerciseProps<TChildProps, TDataName>
>(AddExerciseDocument, {
alias: 'addExercise',
...operationOptions
})
}

/**
* __useAddExerciseMutation__
*
* To run a mutation, you first call `useAddExerciseMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useAddExerciseMutation` 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 [addExerciseMutation, { data, loading, error }] = useAddExerciseMutation({
* variables: {
* moduleId: // value for 'moduleId'
* description: // value for 'description'
* answer: // value for 'answer'
* testStr: // value for 'testStr'
* explanation: // value for 'explanation'
* },
* });
*/
export function useAddExerciseMutation(
baseOptions?: Apollo.MutationHookOptions<
AddExerciseMutation,
AddExerciseMutationVariables
>
) {
const options = { ...defaultOptions, ...baseOptions }
return Apollo.useMutation<AddExerciseMutation, AddExerciseMutationVariables>(
AddExerciseDocument,
options
)
}
export type AddExerciseMutationHookResult = ReturnType<
typeof useAddExerciseMutation
>
export type AddExerciseMutationResult =
Apollo.MutationResult<AddExerciseMutation>
export type AddExerciseMutationOptions = Apollo.BaseMutationOptions<
AddExerciseMutation,
AddExerciseMutationVariables
>
export const AddModuleDocument = gql`
mutation addModule(
$content: String!
Expand Down
26 changes: 26 additions & 0 deletions graphql/queries/addExercise.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { gql } from '@apollo/client'

const ADD_EXERCISE = gql`
mutation addExercise(
$moduleId: Int!
$description: String!
$answer: String!
$testStr: String
$explanation: String
) {
addExercise(
moduleId: $moduleId
description: $description
answer: $answer
testStr: $testStr
explanation: $explanation
) {
id
description
answer
explanation
}
}
`

export default ADD_EXERCISE

1 comment on commit 0dcb658

@vercel
Copy link

@vercel vercel bot commented on 0dcb658 Aug 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.