formik-apollo
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

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

Name Required Type Description
mutate ✔️ Function Performs the form submission.
onCompleted Function Add behavior after a successful submission.
onError Function Add behavior after a failed submission.
getStatus Function Extracts the error message from the GraphQL response.
getErrors Function Extracts field validation errors from the response.

Readme

Keywords

none

Package Sidebar

Install

npm i formik-apollo

Weekly Downloads

19

Version

2.0.3

License

MIT

Unpacked Size

25.8 kB

Total Files

19

Last publish

Collaborators

  • rzane