question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Apollo Mutation component w/ react-final-form

See original GitHub issue

Hi I am trying to make the new Apollo Mutation component which was released in v2.1 work w/ react-final-form. It goes along pretty well so far. But now I finally dealing with server errors. It seems like in Apollo I can only access server errors in the onError callback and not within final-form onSubmit itself. Is there a way to populate submitErrors from within onError?

In other words how to combine Apollo 2.1 + react-final-form the right way?

<Mutation
  mutation={REGISTER_USER}
  onCompleted={result => {
    console.log('result', result);
  }}
  onError={({ graphQLErrors, networkError }) => {
    console.log('graphQLErrors', graphQLErrors[0].message);

    // {'email': 'Email address is invalid.'}
  }}
>
  {registerUser => (
    <FinalForm
      onSubmit={values => {
        registerUser({
          variables: values,
        });
      }}
      initialValues={currentUser}
      render={({
        handleSubmit,
        pristine,
        invalid,
      }: FormRenderProps) => (
        <form onSubmit={handleSubmit}>
          <UsernameField externalLoading={loading} />
          <EmailField />
          <LanguageField />
          <SubmitButton
            initial
            pristine={pristine}
            invalid={invalid}
          >
            Register User
          </SubmitButton>
        </form>
      )}
    />
  )}
</Mutation>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
erikrascommented, Apr 1, 2018

You guys are gonna make me learn Apollo… 😄

Maybe look at @kavink’s work here https://github.com/final-form/react-final-form/issues/23#issuecomment-375581107?

3reactions
erikrascommented, Apr 11, 2018

@soosap Any chance you could whip up a sandbox example I could publicize on the readme?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mutations in Apollo Client - Apollo GraphQL Docs
The useMutation React hook is the primary API for executing mutations in an Apollo application. To execute a mutation, you first call useMutation...
Read more >
Developers - Apollo Mutation component w/ react-final-form -
Hi I am trying to make the new Apollo Mutation component which was released in v2.1 work w/ react-final-form. It goes along pretty...
Read more >
How to pass a react form values into mutation (variables)?
So what worked out for me was: import React from 'react'; import gql from 'graphql-tag'; import { useMutation } from '@apollo/client'; ...
Read more >
Companion Libraries - Final Form Docs
Opinionated way to create forms in React. Data-driven forms that let you focus on what matters: your application. Provide a GraphQL mutation and...
Read more >
Create Messages with React Apollo Mutation Component
Learn how to create messages using React Apollo's Mutation Component.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found