React-apollo: Passing a client parameter in the options of a mutation throws error

Created on 2 Sep 2017  路  3Comments  路  Source: apollographql/react-apollo

I am using this recent feature of adding multiple clients and it is working well so far, but only in this case, the following code breaks when I state the client explicitly in the options of my mutation. I have followed this exact pattern with other components and haven't had any issue.

import { gql } from 'react-apollo';
const networkInterfaceAccounts = createNetworkInterface({
  uri: ACCOUNTS_CLIENT_URL,
});

networkInterfaceAccounts.use([authMiddleware]);

const apolloClientAccounts = new ApolloClient({
  networkInterface: networkInterfaceAccounts,
  reduxRootSelector: state => state.apolloAccounts,
});


export const signupRequestMutation = gql`
  mutation signupRequest($username: String!, $fname: String!, $lname: String!) {
    signupRequest(username: $username, firstName: $fname, lastName: $lname) {
      _id
    }
  }
`;

export const signupRequestOptions = {
  options: () => ({
    client: apolloClientAccounts,
  }),
  props: ({ mutate }) => ({
    signupRequest: ({ username, fname, lname }) => {
      return mutate({
        variables: {
          username,
          fname,
          lname,
        },
      });
    },
  }),
};

And the react component looks like this:

export default compose(
  graphql(signupRequestMutation, signupRequestOptions),
  withRouter,
  reduxForm({
    form: 'signup',
    validate,
  }),
)(SignupForm);

Intended outcome:
As with other components, I expect that the mutation works whether I pass client as an option or not.

  options: () => ({
    client: apolloClientAccounts,
  }),

Actual outcome:
I am getting this error:

Uncaught Error: The operation 'signupRequest' wrapping 'withRouter(ReduxForm)' is expecting a variable: 'username' but it was not found in the props passed to 'Apollo(withRouter(ReduxForm))'

After that, I can submit the form.

Version

All 3 comments

If I change the name of the form in ReduxForm, it works:

reduxForm({
    form: 'signupForm',
    validate,
  }),

I still don't know why, though.

This issue has been automatically labled because it has not had recent activity. If you have not received a response from anyone, please mention the repository maintainer (most likely @jbaxleyiii). It will be closed if no further activity occurs. Thank you for your contributions to React Apollo!

This issue has been automatically closed because it has not had recent activity after being marked as no recent activyt. If you belive this issue is still a problem or should be reopened, please reopen it! Thank you for your contributions to React Apollo!

Was this page helpful?
0 / 5 - 0 ratings