Apollo Mutation component w/ react-final-form
See original GitHub issueHi 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:
- Created 5 years ago
- Comments:11 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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?
@soosap Any chance you could whip up a sandbox example I could publicize on the readme?