graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

Generate and export react-apollo query components props

Open abathellier opened this issue 7 years ago • 2 comments

Is your feature request related to a problem? Please describe. When we want to extend a generated query component with composition we have to generate its props type by ourselves.

For instance:

export const AddToCartComponent = (
  props: Omit<
    Omit<
      ReactApollo.MutationProps<AddToCartMutation, AddToCartMutationVariables>,
      'mutation'
    >,
    'variables'
  > & { variables?: AddToCartMutationVariables }
) => (
  <ReactApollo.Mutation<AddToCartMutation, AddToCartMutationVariables>
    mutation={AddToCartDocument}
    {...props}
  />
);

If i want to wrap it in my own component i have to re-create the props types.

function MyAddToCartComponent(props: Omit<
    Omit<
      ReactApollo.MutationProps<AddToCartMutation, AddToCartMutationVariables>,
      'mutation'
    >,
    'variables'
  > & { variables?: AddToCartMutationVariables }) {
    <AddToCartComponent
      {...props}
      {// some pre-filled stuff}
    >
      {(addToCart, data) => children(addToCart, data)}
    </AddToCartComponent>
}

Describe the solution you'd like Export the generated props.

abathellier avatar May 07 '19 11:05 abathellier

@ardatan Can you please take a look? Maybe we can export it in a different way from react-apollo plugin in order to support this use-case.

dotansimha avatar May 08 '19 07:05 dotansimha

Available in 1.2.0.

dotansimha avatar May 19 '19 12:05 dotansimha