@graphcommerce/react-hook-form 9.0.0-canary.88 → 9.0.0-canary.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.0.0-canary.92
4
+
5
+ ## 9.0.0-canary.91
6
+
7
+ ## 9.0.0-canary.90
8
+
9
+ ### Minor Changes
10
+
11
+ - [#2391](https://github.com/graphcommerce-org/graphcommerce/pull/2391) [`c1fa10f`](https://github.com/graphcommerce-org/graphcommerce/commit/c1fa10f995f562741b7574d465580e5405982a70) - Prevent overwriting custom context in useFormGqlMutation by merging operationOptions before execution. ([@wimvdputten](https://github.com/wimvdputten))
12
+
13
+ ## 9.0.0-canary.89
14
+
3
15
  ## 9.0.0-canary.88
4
16
 
5
17
  ## 9.0.0-canary.87
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/react-hook-form",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "9.0.0-canary.88",
5
+ "version": "9.0.0-canary.92",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -16,9 +16,9 @@
16
16
  },
17
17
  "peerDependencies": {
18
18
  "@apollo/client": "^3",
19
- "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.88",
20
- "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.88",
21
- "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.88",
19
+ "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.92",
20
+ "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.92",
21
+ "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.92",
22
22
  "@mui/utils": "^5",
23
23
  "graphql": "^16.6.0",
24
24
  "react": "^18.2.0",
@@ -5,6 +5,8 @@ import {
5
5
  MutationTuple,
6
6
  TypedDocumentNode,
7
7
  isApolloError,
8
+ MutationHookOptions,
9
+ LazyQueryHookOptions,
8
10
  } from '@apollo/client'
9
11
  import { getOperationName } from '@apollo/client/utilities'
10
12
  import useEventCallback from '@mui/utils/useEventCallback'
@@ -98,6 +100,9 @@ export function useFormGql<Q, V extends FieldValues>(
98
100
  document: TypedDocumentNode<Q, V>
99
101
  form: UseFormReturn<V>
100
102
  tuple: MutationTuple<Q, V> | LazyQueryResultTuple<Q, V>
103
+ operationOptions?:
104
+ | Omit<MutationHookOptions<Q, V>, 'fetchPolicy' | 'variables'>
105
+ | Omit<LazyQueryHookOptions<Q, V>, 'fetchPolicy' | 'variables'>
101
106
  defaultValues?: UseFormProps<V>['defaultValues']
102
107
  skipUnchanged?: boolean
103
108
  } & UseFormGraphQLCallbacks<Q, V>,
@@ -108,6 +113,7 @@ export function useFormGql<Q, V extends FieldValues>(
108
113
  document,
109
114
  form,
110
115
  tuple,
116
+ operationOptions,
111
117
  skipUnchanged,
112
118
  defaultValues,
113
119
  deprecated_useV1 = false,
@@ -181,9 +187,17 @@ export function useFormGql<Q, V extends FieldValues>(
181
187
  submittedVariables.current = variables
182
188
  if (!deprecated_useV1 && loading) controllerRef.current?.abort()
183
189
  controllerRef.current = new window.AbortController()
190
+
184
191
  const result = await execute({
192
+ ...operationOptions,
185
193
  variables,
186
- context: { fetchOptions: { signal: controllerRef.current.signal } },
194
+ context: {
195
+ ...operationOptions?.context,
196
+ fetchOptions: {
197
+ ...operationOptions?.context?.fetchOptions,
198
+ signal: controllerRef.current.signal,
199
+ },
200
+ },
187
201
  })
188
202
 
189
203
  const [, onCompleteError] = await complete(result, variables)
@@ -45,7 +45,7 @@ export function useFormGqlMutation<Q extends Record<string, unknown>, V extends
45
45
  ): UseFormGqlMutationReturn<Q, V> {
46
46
  const form = useForm<V>(options)
47
47
  const tuple = useMutation(document, operationOptions)
48
- const operation = useFormGql({ document, form, tuple, ...options })
48
+ const operation = useFormGql({ document, form, tuple, operationOptions, ...options })
49
49
  const muiRegister = useFormMuiRegister(form)
50
50
  return { ...form, ...operation, muiRegister, valid: {} }
51
51
  }
@@ -16,7 +16,7 @@ export function useFormGqlQuery<Q extends Record<string, unknown>, V extends Fie
16
16
  ): UseFormGqlQueryReturn<Q, V> {
17
17
  const form = useForm<V>(options)
18
18
  const tuple = useLazyQuery(document, operationOptions)
19
- const operation = useFormGql({ document, form, tuple, ...options })
19
+ const operation = useFormGql({ document, form, tuple, operationOptions, ...options })
20
20
  const muiRegister = useFormMuiRegister(form)
21
21
 
22
22
  return { ...form, ...operation, valid: {}, muiRegister }