Apollo breaks when a client is stated in a mutation

195 views Asked by At

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

[email protected] [email protected]

0

There are 0 answers