@graphcommerce/react-hook-form 3.3.3 → 3.3.5
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 +12 -0
- package/package.json +1 -1
- package/src/useFormGql.tsx +3 -6
- package/src/useFormGqlMutation.tsx +1 -0
- package/src/useGqlDocumentHandler.tsx +0 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 3.3.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1665](https://github.com/graphcommerce-org/graphcommerce/pull/1665) [`1f2e14ba8`](https://github.com/graphcommerce-org/graphcommerce/commit/1f2e14ba8b674b87257a123e8cb215157890eb22) Thanks [@paales](https://github.com/paales)! - Make sure the onComplete callback also sends the variables
|
|
8
|
+
|
|
9
|
+
## 3.3.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#1660](https://github.com/graphcommerce-org/graphcommerce/pull/1660) [`75ae24a93`](https://github.com/graphcommerce-org/graphcommerce/commit/75ae24a93bd74e3b9b7efda21ec7ba6fbe9a3a75) Thanks [@paales](https://github.com/paales)! - Remove heuristicEncode for GraphQL input objects provided by react-hook-form
|
|
14
|
+
|
|
3
15
|
## 3.3.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
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": "3.3.
|
|
5
|
+
"version": "3.3.5",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
package/src/useFormGql.tsx
CHANGED
|
@@ -12,10 +12,7 @@ import { UseFormProps, UseFormReturn, UnpackNestedValue, DeepPartial } from 'rea
|
|
|
12
12
|
import diff from './diff'
|
|
13
13
|
import { useGqlDocumentHandler, UseGqlDocumentHandler } from './useGqlDocumentHandler'
|
|
14
14
|
|
|
15
|
-
export type OnCompleteFn<Q> = (
|
|
16
|
-
data: FetchResult<Q>,
|
|
17
|
-
client: ApolloClient<unknown>,
|
|
18
|
-
) => void | Promise<void>
|
|
15
|
+
export type OnCompleteFn<Q, V> = (data: FetchResult<Q>, variables: V) => void | Promise<void>
|
|
19
16
|
|
|
20
17
|
type UseFormGraphQLCallbacks<Q, V> = {
|
|
21
18
|
/**
|
|
@@ -23,7 +20,7 @@ type UseFormGraphQLCallbacks<Q, V> = {
|
|
|
23
20
|
* Mutation. Also allows you to send false to skip submission.
|
|
24
21
|
*/
|
|
25
22
|
onBeforeSubmit?: (variables: V) => V | false | Promise<V | false>
|
|
26
|
-
onComplete?: OnCompleteFn<Q>
|
|
23
|
+
onComplete?: OnCompleteFn<Q, V>
|
|
27
24
|
}
|
|
28
25
|
|
|
29
26
|
export type UseFormGraphQlOptions<Q, V> = UseFormProps<V> & UseFormGraphQLCallbacks<Q, V>
|
|
@@ -81,7 +78,7 @@ export function useFormGql<Q, V>(
|
|
|
81
78
|
// if (variables === false) onInvalid?.(formValues, event)
|
|
82
79
|
|
|
83
80
|
const result = await execute({ variables })
|
|
84
|
-
if (onComplete && result.data) await onComplete(result,
|
|
81
|
+
if (onComplete && result.data) await onComplete(result, variables)
|
|
85
82
|
|
|
86
83
|
// Reset the state of the form if it is unmodified afterwards
|
|
87
84
|
if (typeof diff(form.getValues(), formValues) === 'undefined')
|
|
@@ -26,6 +26,7 @@ export function assertFormGqlOperation<V, Q = Record<string, unknown>>(
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/** Bindings between react-hook-form's useForm and Apollo Client's useMutation hook. */
|
|
29
30
|
export function useFormGqlMutation<Q, V>(
|
|
30
31
|
document: TypedDocumentNode<Q, V>,
|
|
31
32
|
options: UseFormGraphQlOptions<Q, V> = {},
|
|
@@ -116,20 +116,8 @@ export function handlerFactory<Q, V>(document: TypedDocumentNode<Q, V>): UseGqlD
|
|
|
116
116
|
const required = requiredPartial as Required
|
|
117
117
|
const encoding = encodingPartial as Encoding
|
|
118
118
|
|
|
119
|
-
function heuristicEncode(val: string) {
|
|
120
|
-
if (Number(val).toString() === val) return Number(val)
|
|
121
|
-
if (val === 'true') return true
|
|
122
|
-
if (val === 'false') return false
|
|
123
|
-
return val
|
|
124
|
-
}
|
|
125
|
-
|
|
126
119
|
function encodeItem(enc: FieldTypes, val: unknown) {
|
|
127
120
|
if (Array.isArray(val)) return val.map((v, i) => encodeItem(enc[i], v))
|
|
128
|
-
if (val && typeof val === 'object') {
|
|
129
|
-
return Object.fromEntries(
|
|
130
|
-
Object.entries(val).map(([key, v]) => [key, heuristicEncode(v as string)]),
|
|
131
|
-
)
|
|
132
|
-
}
|
|
133
121
|
if (enc === 'Boolean') return Boolean(val)
|
|
134
122
|
if (enc === 'Float' || enc === 'Int') return Number(val)
|
|
135
123
|
return val
|