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

@@ -5,7 +5,13 @@ import rest from '../../rest';
import Auth from '../../Auth';
import { extractKeysAndInclude } from './parseClassTypes';
const getUserFromSessionToken = async (config, info, queryInfo) => {
const getUserFromSessionToken = async (
config,
info,
queryInfo,
keysPrefix,
validatedToken
) => {
if (!info || !info.sessionToken) {
throw new Parse.Error(
Parse.Error.INVALID_SESSION_TOKEN,
@@ -13,20 +19,42 @@ const getUserFromSessionToken = async (config, info, queryInfo) => {
);
}
const sessionToken = info.sessionToken;
const selectedFields = getFieldNames(queryInfo);
const selectedFields = getFieldNames(queryInfo)
.filter(field => field.startsWith(keysPrefix))
.map(field => field.replace(keysPrefix, ''));
const keysAndInclude = extractKeysAndInclude(selectedFields);
const { keys } = keysAndInclude;
let { include } = keysAndInclude;
if (validatedToken && !keys && !include) {
return {
sessionToken,
};
} else if (keys && !include) {
include = 'user';
}
const options = {};
if (keys) {
options.keys = keys
.split(',')
.map(key => `user.${key}`)
.join(',');
}
if (include) {
options.include = include
.split(',')
.map(included => `user.${included}`)
.join(',');
}
const { include } = extractKeysAndInclude(selectedFields);
const response = await rest.find(
config,
Auth.master(config),
'_Session',
{ sessionToken },
{
include: include
.split(',')
.map(included => `user.${included}`)
.join(','),
},
options,
info.clientVersion
);
if (
@@ -40,8 +68,10 @@ const getUserFromSessionToken = async (config, info, queryInfo) => {
);
} else {
const user = response.results[0].user;
user.sessionToken = sessionToken;
return user;
return {
sessionToken,
user,
};
}
};
@@ -59,7 +89,13 @@ const load = parseGraphQLSchema => {
async resolve(_source, _args, context, queryInfo) {
try {
const { config, info } = context;
return await getUserFromSessionToken(config, info, queryInfo);
return await getUserFromSessionToken(
config,
info,
queryInfo,
'user.',
false
);
} catch (e) {
parseGraphQLSchema.handleError(e);
}