Relay: [Relay Modern compat] RANGE_ADD on connections with arguments

Created on 3 Jul 2017  路  3Comments  路  Source: facebook/relay

Based on this https://github.com/facebook/relay/issues/1462

I have the following query in one of my components:

fragment on Viewer {
   user {
   events(first: 10, date: $date) {
      edges {
         node {
            id
            date
            title
        }
     }
   }
}
}     

date is a DateFilter

input DateFilter {
  # start date
  start: String!

  # end date
  end: String!
}   

This is the config I'm using in my relay mutation

function getConfigs(personId) {
  return [
    {
      type: 'RANGE_ADD',
      parentName: 'user',
      parentID: userId,
      connectionName: 'events',
      edgeName: 'eventEdge',
      rangeBehaviors: {
        '': 'prepend',
      },
    },
  ];
}

I'm using relay compat mode

import { graphql, commitMutation } from 'react-relay/compat';

const mutation = graphql`
  mutation EventAddMutation($input: EventAddInput!) {
    EventAdd(input: $input) {
      eventEdge {
        __typename
        cursor
        node {
          id
          title
       }
     }      
      error
    }
  }
`;

Most helpful comment

rangeBehaviors: (args) => {
return 'prepend';
},

using as a function works great

All 3 comments

You can do something like:

rangeBehaviors: {
        'date(<insert date param here>)': 'prepend',
      },

is it possible to add an edge to all connections in relay classic?

rangeBehaviors: (args) => {
return 'prepend';
},

using as a function works great

Was this page helpful?
0 / 5 - 0 ratings

Related issues

luongthanhlam picture luongthanhlam  路  3Comments

scotmatson picture scotmatson  路  3Comments

jstejada picture jstejada  路  3Comments

rayronvictor picture rayronvictor  路  3Comments

mike-marcacci picture mike-marcacci  路  3Comments