relay: rangeBehaviors should be a function that returns a GraphQLMutatorConstants.RANGE_OPERATION

As mentioned by @johanobergman in #604 and similar to what @AndrewIngram proposed in #538, let’s make rangeBehaviors a function that receives the connection arguments and returns one of GraphQLMutatorConstants.RANGE_OPERATIONS.

getConfigs: [{
  /* ... */
  rangeBehaviors(
    fieldArgs: {[argName: string]: argValue: string}
  ): ?$Enum<typeof GraphQLMutatorConstants.RANGE_OPERATIONS> {
    return isBefore(fieldArgs.startDate, fieldArgs.endDate) ?
      GraphQLMutatorConstants.RANGE_OPERATIONS.APPEND :
      GraphQLMutatorConstants.RANGE_OPERATIONS.PREPEND;
  }
  /* ... */
}]

Add an appropriate deprecation warning to RelayDeprecated.

Bonus: write a jscodeshift codemod that will mod this:

rangeBehaviors: {
  'foo(true)': 'prepend',
  'foo(false)': 'append',
}

…to this:

rangeBehaviors({foo}) {
  if (foo === true) {
    return 'prepend';
  } else if (foo === false) {
    return 'append';
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 15 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@brysgo Good catch, @xuorig has put up #1216 to address this.