2.0.3 • Published 4 years ago

formik-apollo v2.0.3

Weekly downloads
18
License
MIT
Repository
github
Last release
4 years ago

formik-apollo

Build Version Size License

A React hook to extract validation errors from a GraphQL request and apply them to a Formik form.

useSubmit

This is a React hook that will automatically extract validation errors from a failed GraphQL response and apply them to a Formik form.

const handleSubmit = useSubmit({
  mutate(data, actions) {
    return client.mutate(MyMutation, { variables: { data } });
  }
});

On the server side, a failed GraphQL response should look like this:

{
  "errors": [
    {
      "message": "Some generic error message",
      "extensions": {
        "code": "VALIDATION_ERROR",
        "problems": {
          "email": ["is required"]
        }
      }
    }
  ]
}

Options

NameRequiredTypeDescription
mutate✔️FunctionPerforms the form submission.
onCompletedFunctionAdd behavior after a successful submission.
onErrorFunctionAdd behavior after a failed submission.
getStatusFunctionExtracts the error message from the GraphQL response.
getErrorsFunctionExtracts field validation errors from the response.
2.0.3

4 years ago

2.0.3-alpha.1

4 years ago

2.0.3-alpha.0

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.0.0

5 years ago

0.6.12

5 years ago

0.6.11

5 years ago

0.6.10

5 years ago

0.6.9

5 years ago

0.6.8

5 years ago

0.6.7

5 years ago

0.6.6

5 years ago