allow rangeBehaviors to be defined as a function #1054

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
4 participants
@xuorig
Contributor

xuorig commented Apr 16, 2016

New PR for #639
Fix for #615, proposed in #538

Allows rangeBehaviors to be defined as a function that receives the connection arguments and returns one of GraphQLMutatorConstants.RANGE_OPERATIONS.

changes summary:

  • added a getRangeBehavior module that will return a rangeBehavior depdending on rangeBehaviors config and calls passed by argument.
  • changed RelayQuery's getRangeBehaviorKey to getRangeBehaviorCalls so it can be reused by a function or plain object rangeBehaviors config.
  • Added some documentation on using a function as rangeBehaviors config.
  • Modified todo example to use a function.
src/mutation/RelayMutationQuery.js
const flattenRelayQuery = require('flattenRelayQuery');
const forEachObject = require('forEachObject');
const nullthrows = require('nullthrows');
const inferRelayFieldsFromData = require('inferRelayFieldsFromData');
const intersectRelayQuery = require('intersectRelayQuery');
+const getRangeBehavior = require('getRangeBehavior');

This comment has been minimized.

@josephsavona

josephsavona Apr 16, 2016

Contributor

nit: alpha ordering

@josephsavona

josephsavona Apr 16, 2016

Contributor

nit: alpha ordering

src/mutation/RelayMutationQuery.js
@@ -24,12 +24,14 @@ import type RelayQueryTracker from 'RelayQueryTracker';
const RelayRecord = require('RelayRecord');
import type {Variables} from 'RelayTypes';
const {REFETCH} = require('GraphQLMutatorConstants');
+import type RelayRecordStore from 'RelayRecordStore';

This comment has been minimized.

@josephsavona

josephsavona Apr 16, 2016

Contributor

unused?

@josephsavona

josephsavona Apr 16, 2016

Contributor

unused?

@xuorig

This comment has been minimized.

Show comment
Hide comment
@xuorig

xuorig Apr 16, 2016

Contributor

addressed your comments @josephsavona

Not sure about the CI Failure ?

Contributor

xuorig commented Apr 16, 2016

addressed your comments @josephsavona

Not sure about the CI Failure ?

@xuorig

This comment has been minimized.

Show comment
Hide comment
@xuorig

xuorig Apr 16, 2016

Contributor

Somehow I'm getting this Flow type error on master too ¯_(ツ)_/¯

Contributor

xuorig commented Apr 16, 2016

Somehow I'm getting this Flow type error on master too ¯_(ツ)_/¯

@xuorig

This comment has been minimized.

Show comment
Hide comment
@xuorig

xuorig Apr 21, 2016

Contributor

Rebased and got 🍏, I know this is a fairly large PR, but any comments ? cc @josephsavona

Contributor

xuorig commented Apr 21, 2016

Rebased and got 🍏, I know this is a fairly large PR, but any comments ? cc @josephsavona

src/query/RelayQuery.js
+
+ return this.getCallsWithValues().filter(arg => {
+ return this._isCoreArg(arg);
+ });

This comment has been minimized.

@josephsavona

josephsavona Apr 21, 2016

Contributor

__rangeBehaviorKey__ was previously used to memoize the result of this field. Let's either removing that property altogether or renaming it to __rangeBehaviorCalls__ and restoring the memoization (preference toward the latter).

@josephsavona

josephsavona Apr 21, 2016

Contributor

__rangeBehaviorKey__ was previously used to memoize the result of this field. Let's either removing that property altogether or renaming it to __rangeBehaviorCalls__ and restoring the memoization (preference toward the latter).

src/query/RelayQuery.js
- */
- getRangeBehaviorKey(): string {
+ * An array of calls excluding Core args to use with rangeBehavior
+ * functions.

This comment has been minimized.

@josephsavona

josephsavona Apr 21, 2016

Contributor

maybe keep the explanation of what arguments are excluded

@josephsavona

josephsavona Apr 21, 2016

Contributor

maybe keep the explanation of what arguments are excluded

+ const rangeBehavior = getRangeBehavior(rangeBehaviors, calls);
+ expect(rangeBehavior).toBe('append');
+ });
+ });

This comment has been minimized.

@josephsavona

josephsavona Apr 21, 2016

Contributor

nit: it would be good to test a non-matching case too

@josephsavona

josephsavona Apr 21, 2016

Contributor

nit: it would be good to test a non-matching case too

@josephsavona

This comment has been minimized.

Show comment
Hide comment
@josephsavona

josephsavona Apr 21, 2016

Contributor

@xuorig sorry for the delay in review. this looks pretty solid, just a few nits and we should be good to go.

Contributor

josephsavona commented Apr 21, 2016

@xuorig sorry for the delay in review. this looks pretty solid, just a few nits and we should be good to go.

@xuorig

This comment has been minimized.

Show comment
Hide comment
@xuorig

xuorig Apr 21, 2016

Contributor

addressed your comments @josephsavona :)

Contributor

xuorig commented Apr 21, 2016

addressed your comments @josephsavona :)

@josephsavona

This comment has been minimized.

Show comment
Hide comment
Contributor

josephsavona commented Apr 21, 2016

@josephsavona

This comment has been minimized.

Show comment
Hide comment
@josephsavona

josephsavona Apr 21, 2016

Contributor

thanks!

Contributor

josephsavona commented Apr 21, 2016

thanks!

@facebook-github-bot

This comment has been minimized.

Show comment
Hide comment
@facebook-github-bot

facebook-github-bot Apr 21, 2016

Thanks for importing. If you are an FB employee go to Phabricator to review.

Thanks for importing. If you are an FB employee go to Phabricator to review.

@ghost ghost closed this in 56e52d3 Apr 28, 2016

@josephsavona

This comment has been minimized.

Show comment
Hide comment
@josephsavona

josephsavona Apr 28, 2016

Contributor

@xuorig thanks for this!

Contributor

josephsavona commented Apr 28, 2016

@xuorig thanks for this!

@tim-field

This comment has been minimized.

Show comment
Hide comment
@tim-field

tim-field Oct 17, 2016

Hello, is this likely to be released soon ? Looks like a really useful feature.

Hello, is this likely to be released soon ? Looks like a really useful feature.

@josephsavona

This comment has been minimized.

Show comment
Hide comment
@josephsavona

josephsavona Oct 20, 2016

Contributor

This is included in the latest release.

Contributor

josephsavona commented Oct 20, 2016

This is included in the latest release.

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment