react-apollo icon indicating copy to clipboard operation
react-apollo copied to clipboard

config.skip not working on graphql()mutations - does work on graphql()query

Open carllippert opened this issue 8 years ago • 8 comments

Intended outcome:

Config.skip should allow me to call this.props.select({id}) in many different contexts. This is a reusable selection modal. It worked with react-apollo 2.0.4.

export default compose(
  graphql(mountedPens, {
            skip: (props) => props.navigation.state.params.modalType != "FeedingPen",
            props: ({data: { mountedPens, loading }}) => ({ data: mountedPens, loading }),
            }),
  graphql(mountedPens, {
            skip: (props) => props.navigation.state.params.modalType != "Pen",
            props: ({data: { mountedPens, loading }}) => ({ data: mountedPens, loading }),
            }),
  graphql(setSelectedPen, {
            skip: (props) => props.navigation.state.params.modalType != "Pen",
            props: ({ mutate }) => ({
              select: ({id}) => mutate({ variables: { pen_id: id } }),
            })
          }),
  graphql(setActiveBatchPen, {
            skip: (props) => props.navigation.state.params.modalType != "FeedingPen",
            props: ({ mutate }) => ({
              select: ({id}) => mutate({ variables: { pen_id: id } }),
            })
          }),
  graphql(mountedRations, {
            skip: (props) => props.navigation.state.params.modalType != "Ration",
            props: ({data: { mountedRations, loading }}) => ({ data: mountedRations, loading }),
            }),
    graphql(setSelectedRation, {
            skip: (props) => props.navigation.state.params.modalType != "Ration",
            props: ({ mutate }) => ({
              select: ({id}) => mutate({ variables: { ration_type_id: id } }),
            })
          }),
    graphql(mountedVendors, {
            skip: (props) => props.navigation.state.params.modalType != "Vendor",
            props: ({ data: { mountedVendors, loading }  }) => ({ data: mountedVendors, loading }),
          }),
    graphql(setSelectedVendor, {
            skip: (props) => props.navigation.state.params.modalType != "Vendor",
            props: ({ mutate }) => ({
              select: ({id}) => mutate({ variables: { vendor_id: id } }),
            })
          }),
  graphql(setSelectedIngredient, {
            skip: (props) => props.navigation.state.params.modalType != "Ingredient",
            props: ({ mutate }) => ({
              select: ({id}) => mutate({ variables: { ingredient_id: id } }),
            })
          }),
  graphql(mountedIngredients, {
            skip: props => props.navigation.state.params.modalType != "Ingredient",
            props: ({ data: { mountedIngredients, loading }  }) => ({ data: mountedIngredients, loading }),
        }),
)(SelectionModal);

Actual outcome:

Last mutation in the compose functions always gets called with this.props.select({ id }). As I understand compose calls functions backwards so this means the first mutation it see's its calling and ignoring the skip function.

Downgrading back to 2.0.4 did in fact fix it too. Docs don't seem to reflect a change in implementation in this area as far as I can tell.

Version

  • apollo-client@<2.2.8>
  • react-apollo@<2.1.3>