Add isPlural() method to RelayQueryRoot
Summary: Returns true when the root field wraps a `GraphQLList` Reviewed By: josephsavona Differential Revision: D2635462 fb-gh-sync-id: 40b4dfa162db1fcbf86672ff4cdbf0652372b582
This commit is contained in:
1 parent
395fa7bd03
commit
12139c8da1
10 files changed
+30
-3
No files matched your search
@@ -16,7 +16,7 @@
|
||||
|
||||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
||||
|
||||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
||||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
|
||||
@@ -90,6 +90,9 @@ var RelayQLPrinter = (function () {
|
||||
}
|
||||
var selections = this.printSelections(rootField, requisiteFields);
|
||||
var metadata = {};
|
||||
if (rootFieldType.isList()) {
|
||||
metadata.isPlural = true;
|
||||
}
|
||||
invariant(rootFieldArgs.length <= 1, 'Invalid root field `%s`; Relay only supports root fields with zero ' + 'or one argument.', rootField.getName());
|
||||
var calls = NULL;
|
||||
if (rootFieldArgs.length === 1) {
|
||||
|
||||
@@ -94,6 +94,9 @@ class RelayQLPrinter {
|
||||
}
|
||||
const selections = this.printSelections(rootField, requisiteFields);
|
||||
const metadata = {};
|
||||
if (rootFieldType.isList()) {
|
||||
metadata.isPlural = true;
|
||||
}
|
||||
invariant(
|
||||
rootFieldArgs.length <= 1,
|
||||
'Invalid root field `%s`; Relay only supports root fields with zero ' +
|
||||
|
||||
@@ -44,6 +44,7 @@ var foo = (function () {
|
||||
fieldName: "nodes",
|
||||
kind: "Query",
|
||||
metadata: {
|
||||
isPlural: true,
|
||||
identifyingArgName: "ids"
|
||||
},
|
||||
name: "Args"
|
||||
|
||||
@@ -33,6 +33,7 @@ var q = (function () {
|
||||
fieldName: 'search',
|
||||
kind: 'Query',
|
||||
metadata: {
|
||||
isPlural: true,
|
||||
identifyingArgName: 'query',
|
||||
identifyingArgType: '[SearchInput!]'
|
||||
},
|
||||
|
||||
@@ -43,6 +43,7 @@ var x = (function () {
|
||||
fieldName: 'nodes',
|
||||
kind: 'Query',
|
||||
metadata: {
|
||||
isPlural: true,
|
||||
identifyingArgName: 'ids'
|
||||
},
|
||||
name: 'QueryWithVarArgs'
|
||||
|
||||
@@ -131,6 +131,7 @@ export type ConcreteQuery = {
|
||||
metadata: {
|
||||
identifyingArgName?: ?string;
|
||||
identifyingArgType?: ?string;
|
||||
isPlural?: ?boolean;
|
||||
};
|
||||
name: string;
|
||||
};
|
||||
|
||||
@@ -190,6 +190,7 @@ const QueryBuilder = {
|
||||
identifyingArgName?: ?string;
|
||||
identifyingArgType?: ?string;
|
||||
isDeferred?: ?boolean;
|
||||
isPlural?: ?boolean;
|
||||
};
|
||||
name: string;
|
||||
}): ConcreteQuery {
|
||||
@@ -225,6 +226,7 @@ const QueryBuilder = {
|
||||
metadata: {
|
||||
identifyingArgName,
|
||||
identifyingArgType: metadata.identifyingArgType,
|
||||
isPlural: metadata.isPlural,
|
||||
},
|
||||
name: partialQuery.name,
|
||||
};
|
||||
|
||||
@@ -540,6 +540,10 @@ class RelayQueryRoot extends RelayQueryNode {
|
||||
return !!(this.__concreteNode__: ConcreteQuery).isDeferred;
|
||||
}
|
||||
|
||||
isPlural(): boolean {
|
||||
return !!(this.__concreteNode__: ConcreteQuery).metadata.isPlural;
|
||||
}
|
||||
|
||||
getDeferredFragmentNames(): FragmentNames {
|
||||
var fragmentNames = this.__deferredFragmentNames__;
|
||||
if (!fragmentNames) {
|
||||
|
||||
@@ -45,7 +45,10 @@ describe('RelayQueryRoot', () => {
|
||||
}
|
||||
}
|
||||
`);
|
||||
usernames.__concreteNode__.metadata = {identifyingArgName: 'names'};
|
||||
usernames.__concreteNode__.metadata = {
|
||||
isPlural: true,
|
||||
identifyingArgName: 'names',
|
||||
};
|
||||
});
|
||||
|
||||
it('has a unique ID', () => {
|
||||
@@ -242,7 +245,10 @@ describe('RelayQueryRoot', () => {
|
||||
}
|
||||
}
|
||||
`);
|
||||
usernames2.__concreteNode__.metadata = {identifyingArgName: 'names'};
|
||||
usernames2.__concreteNode__.metadata = {
|
||||
isPlural: true,
|
||||
identifyingArgName: 'names',
|
||||
};
|
||||
|
||||
expect(me.equals(me2)).toBe(true);
|
||||
expect(usernames.equals(usernames2)).toBe(true);
|
||||
@@ -460,6 +466,11 @@ describe('RelayQueryRoot', () => {
|
||||
expect(identifyingQuery.getStorageKey()).toBe('username');
|
||||
});
|
||||
|
||||
it('identifies itself as plural or not', () => {
|
||||
expect(me.isPlural()).toBe(false);
|
||||
expect(usernames.isPlural()).toBe(true);
|
||||
});
|
||||
|
||||
/*
|
||||
Come a time when root fields support more than just identifying arguments,
|
||||
write a test to ensure that non-identifying args don't get stripped out.
|
||||
|
||||
Reference in new issue
Block a user