Relay Spec (#6089)

* Install graphql-relay

* Add relayNodeInterface to ParseGraphQLSchema

* Add support to global id

* Add support to global id in other operations

* Fix sort by glboal id

* Fix where by global id

* Introduce IdWhereInput

* Add Relay object identification tests

* Client mutation id on createFile mutation

* Client mutation id on callCloudCode mutation

* Client mutation id on signUp mutation

* Client mutation id on logIn mutation

* Client mutation id on logOut mutation

* Client mutation id on createClass mutation

* Client mutation id on updateClass mutation

* Client mutation id on deleteClass mutation

* Client mutation id on create object mutation

* Improve Viewer type

* Client mutation id on update object mutation

* Client mutation id on delete object mutation

* Introducing connections

* Fix tests

* Add pagination test

* Fix file location

* Fix postgres tests

* Add comments

* Tests to calculateSkipAndLimit
This commit is contained in:
Antonio Davi Macedo Coelho de Castro
2019-12-01 21:43:08 -08:00
committed by GitHub
parent 67e3c33ffe
commit a9066e20dc
22 changed files with 4685 additions and 2816 deletions

View File

@@ -1,4 +1,5 @@
import { GraphQLNonNull } from 'graphql';
import { fromGlobalId } from 'graphql-relay';
import getFieldNames from 'graphql-list-fields';
import pluralize from 'pluralize';
import * as defaultGraphQLTypes from './defaultGraphQLTypes';
@@ -14,11 +15,18 @@ const getParseClassQueryConfig = function(
};
const getQuery = async (className, _source, args, context, queryInfo) => {
const { id, options } = args;
let { id } = args;
const { options } = args;
const { readPreference, includeReadPreference } = options || {};
const { config, auth, info } = context;
const selectedFields = getFieldNames(queryInfo);
const globalIdObject = fromGlobalId(id);
if (globalIdObject.type === className) {
id = globalIdObject.id;
}
const { keys, include } = extractKeysAndInclude(selectedFields);
return await objectsQueries.getObject(
@@ -58,7 +66,7 @@ const load = function(
parseGraphQLSchema.addGraphQLQuery(getGraphQLQueryName, {
description: `The ${getGraphQLQueryName} query can be used to get an object of the ${graphQLClassName} class by its id.`,
args: {
id: defaultGraphQLTypes.OBJECT_ID_ATT,
id: defaultGraphQLTypes.GLOBAL_OR_OBJECT_ID_ATT,
options: defaultGraphQLTypes.READ_OPTIONS_ATT,
},
type: new GraphQLNonNull(
@@ -82,11 +90,20 @@ const load = function(
description: `The ${findGraphQLQueryName} query can be used to find objects of the ${graphQLClassName} class.`,
args: classGraphQLFindArgs,
type: new GraphQLNonNull(
classGraphQLFindResultType || defaultGraphQLTypes.FIND_RESULT
classGraphQLFindResultType || defaultGraphQLTypes.OBJECT
),
async resolve(_source, args, context, queryInfo) {
try {
const { where, order, skip, limit, options } = args;
const {
where,
order,
skip,
first,
after,
last,
before,
options,
} = args;
const {
readPreference,
includeReadPreference,
@@ -97,8 +114,8 @@ const load = function(
const { keys, include } = extractKeysAndInclude(
selectedFields
.filter(field => field.includes('.'))
.map(field => field.slice(field.indexOf('.') + 1))
.filter(field => field.startsWith('edges.node.'))
.map(field => field.replace('edges.node.', ''))
);
const parseOrder = order && order.join(',');
@@ -107,7 +124,10 @@ const load = function(
where,
parseOrder,
skip,
limit,
first,
after,
last,
before,
keys,
include,
false,
@@ -117,7 +137,7 @@ const load = function(
config,
auth,
info,
selectedFields.map(field => field.split('.', 1)[0]),
selectedFields,
parseClass.fields
);
} catch (e) {