Graphql-code-generator: TypeScript React Apollo makes `variables` prop required on Mutation components

Created on 18 Apr 2019  路  1Comment  路  Source: dotansimha/graphql-code-generator

When generating mutation components the variables prop is now always required, which resulted in a lot of type exceptions in our code base.

This GraphQL mutation:

mutation addPersonMutation($name: String!) {
  addPerson(name: $name) {
    id
    name
  }
}

is generated like this:

export const AddPersonMutationComponent = (
  props: Omit<
    Omit<
      ReactApollo.MutationProps<
        AddPersonMutationMutation,
        AddPersonMutationMutationVariables
      >,
      'mutation'
    >,
    'variables'
  > & { variables: AddPersonMutationMutationVariables }, // variables should be optional for Mutations
) => (
  <ReactApollo.Mutation<
    AddPersonMutationMutation,
    AddPersonMutationMutationVariables
  >
    mutation={AddPersonMutationDocument}
    {...props}
  />
);

My codegen.yml config file:

overwrite: true
schema: 'http://localhost:3000/graphql'
documents:
  - 'src/**/*.query.graphql'
  - 'src/**/*.mutation.graphql'
generates:
  src/generated/graphql.tsx:
    plugins:
      - typescript
      - typescript-operations
      - 'typescript-react-apollo'
    config:
      scalars:
        Date: number
      noGraphQLTag: false

It's maybe related to PR #1687

bug plugins waiting-for-release

Most helpful comment

Fixed in 1.1.1 馃帀

>All comments

Fixed in 1.1.1 馃帀

Was this page helpful?
0 / 5 - 0 ratings