Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom InputTypes with react-apollo

I'm trying to execute a mutation query that requires a custom input type on the client. Currently it looks something like this:

import { graphql } from 'react-apollo';
...
const graphQuery = graphql(gql`
  input UserSignUpInput {
    firstName: String!,
    lastName: String!,
    email: String!,
    password: String!
  }
  mutation userSignUp($input: UserSignUpInput!) {
    createUserByEmail(input: $input) {
      authToken
    }
  }`, {
  props: ({ mutate }) => ({
    signup: (firstName, lastName, email, password) =>
      mutate({ variables: { input: { firstName, lastName, email, password } } }),
  }),
});
...

However I'm getting the error that I'm not allowed to define input types in the query. My question is: How do I define these complex input types? It doesn't seem like I'm able to provide a Schema to ApolloClient..

like image 540
Andreas Jarbol Avatar asked Oct 28 '25 08:10

Andreas Jarbol


1 Answers

The correct syntax on the client side is just:

gql`
  mutation userSignUp($input: UserSignUpInput!) {
    createUserByEmail(input: $input) {
      authToken
    }
  }
`

As your input UserSignUpInput is defined on the server, everything is going fine.

server

input UserSignUpInput {
  firstName: String!,
  lastName: String!,
  email: String!,
  password: String!
}
like image 168
user3142695 Avatar answered Oct 31 '25 12:10

user3142695



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!