Skip to content

Commit 7b7bfb3

Browse files
committed
feat: Create addExercise hook
1 parent e0a16bf commit 7b7bfb3

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed

graphql/index.tsx

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,25 @@ export type AddCommentMutation = {
467467
addComment?: { __typename?: 'Comment'; id: number } | null
468468
}
469469

470+
export type AddExerciseMutationVariables = Exact<{
471+
moduleId: Scalars['Int']
472+
description: Scalars['String']
473+
answer: Scalars['String']
474+
testStr?: InputMaybe<Scalars['String']>
475+
explanation?: InputMaybe<Scalars['String']>
476+
}>
477+
478+
export type AddExerciseMutation = {
479+
__typename?: 'Mutation'
480+
addExercise: {
481+
__typename?: 'Exercise'
482+
id: number
483+
description: string
484+
answer: string
485+
explanation?: string | null
486+
}
487+
}
488+
470489
export type AddModuleMutationVariables = Exact<{
471490
content: Scalars['String']
472491
lessonId: Scalars['Int']
@@ -2201,6 +2220,106 @@ export type AddCommentMutationOptions = Apollo.BaseMutationOptions<
22012220
AddCommentMutation,
22022221
AddCommentMutationVariables
22032222
>
2223+
export const AddExerciseDocument = gql`
2224+
mutation addExercise(
2225+
$moduleId: Int!
2226+
$description: String!
2227+
$answer: String!
2228+
$testStr: String
2229+
$explanation: String
2230+
) {
2231+
addExercise(
2232+
moduleId: $moduleId
2233+
description: $description
2234+
answer: $answer
2235+
testStr: $testStr
2236+
explanation: $explanation
2237+
) {
2238+
id
2239+
description
2240+
answer
2241+
explanation
2242+
}
2243+
}
2244+
`
2245+
export type AddExerciseMutationFn = Apollo.MutationFunction<
2246+
AddExerciseMutation,
2247+
AddExerciseMutationVariables
2248+
>
2249+
export type AddExerciseProps<
2250+
TChildProps = {},
2251+
TDataName extends string = 'mutate'
2252+
> = {
2253+
[key in TDataName]: Apollo.MutationFunction<
2254+
AddExerciseMutation,
2255+
AddExerciseMutationVariables
2256+
>
2257+
} & TChildProps
2258+
export function withAddExercise<
2259+
TProps,
2260+
TChildProps = {},
2261+
TDataName extends string = 'mutate'
2262+
>(
2263+
operationOptions?: ApolloReactHoc.OperationOption<
2264+
TProps,
2265+
AddExerciseMutation,
2266+
AddExerciseMutationVariables,
2267+
AddExerciseProps<TChildProps, TDataName>
2268+
>
2269+
) {
2270+
return ApolloReactHoc.withMutation<
2271+
TProps,
2272+
AddExerciseMutation,
2273+
AddExerciseMutationVariables,
2274+
AddExerciseProps<TChildProps, TDataName>
2275+
>(AddExerciseDocument, {
2276+
alias: 'addExercise',
2277+
...operationOptions
2278+
})
2279+
}
2280+
2281+
/**
2282+
* __useAddExerciseMutation__
2283+
*
2284+
* To run a mutation, you first call `useAddExerciseMutation` within a React component and pass it any options that fit your needs.
2285+
* When your component renders, `useAddExerciseMutation` returns a tuple that includes:
2286+
* - A mutate function that you can call at any time to execute the mutation
2287+
* - An object with fields that represent the current status of the mutation's execution
2288+
*
2289+
* @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;
2290+
*
2291+
* @example
2292+
* const [addExerciseMutation, { data, loading, error }] = useAddExerciseMutation({
2293+
* variables: {
2294+
* moduleId: // value for 'moduleId'
2295+
* description: // value for 'description'
2296+
* answer: // value for 'answer'
2297+
* testStr: // value for 'testStr'
2298+
* explanation: // value for 'explanation'
2299+
* },
2300+
* });
2301+
*/
2302+
export function useAddExerciseMutation(
2303+
baseOptions?: Apollo.MutationHookOptions<
2304+
AddExerciseMutation,
2305+
AddExerciseMutationVariables
2306+
>
2307+
) {
2308+
const options = { ...defaultOptions, ...baseOptions }
2309+
return Apollo.useMutation<AddExerciseMutation, AddExerciseMutationVariables>(
2310+
AddExerciseDocument,
2311+
options
2312+
)
2313+
}
2314+
export type AddExerciseMutationHookResult = ReturnType<
2315+
typeof useAddExerciseMutation
2316+
>
2317+
export type AddExerciseMutationResult =
2318+
Apollo.MutationResult<AddExerciseMutation>
2319+
export type AddExerciseMutationOptions = Apollo.BaseMutationOptions<
2320+
AddExerciseMutation,
2321+
AddExerciseMutationVariables
2322+
>
22042323
export const AddModuleDocument = gql`
22052324
mutation addModule(
22062325
$content: String!

graphql/queries/addExercise.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { gql } from '@apollo/client'
2+
3+
const ADD_EXERCISE = gql`
4+
mutation addExercise(
5+
$moduleId: Int!
6+
$description: String!
7+
$answer: String!
8+
$testStr: String
9+
$explanation: String
10+
) {
11+
addExercise(
12+
moduleId: $moduleId
13+
description: $description
14+
answer: $answer
15+
testStr: $testStr
16+
explanation: $explanation
17+
) {
18+
id
19+
description
20+
answer
21+
explanation
22+
}
23+
}
24+
`
25+
26+
export default ADD_EXERCISE

0 commit comments

Comments
 (0)