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 { GraphQLNonNull, GraphQLString } from 'graphql';
import { mutationWithClientMutationId } from 'graphql-relay';
import UsersRouter from '../../Routers/UsersRouter';
import * as objectsMutations from '../helpers/objectsMutations';
import { getUserFromSessionToken } from './usersQueries';
@@ -10,110 +11,166 @@ const load = parseGraphQLSchema => {
return;
}
parseGraphQLSchema.addGraphQLMutation(
'signUp',
{
description: 'The signUp mutation can be used to sign the user up.',
args: {
fields: {
descriptions: 'These are the fields of the user.',
type: parseGraphQLSchema.parseClassTypes['_User'].signUpInputType,
},
},
type: new GraphQLNonNull(parseGraphQLSchema.viewerType),
async resolve(_source, args, context, mutationInfo) {
try {
const { fields } = args;
const { config, auth, info } = context;
const { sessionToken } = await objectsMutations.createObject(
'_User',
fields,
config,
auth,
info
);
info.sessionToken = sessionToken;
return await getUserFromSessionToken(config, info, mutationInfo);
} catch (e) {
parseGraphQLSchema.handleError(e);
}
const signUpMutation = mutationWithClientMutationId({
name: 'SignUp',
description:
'The signUp mutation can be used to create and sign up a new user.',
inputFields: {
userFields: {
descriptions:
'These are the fields of the new user to be created and signed up.',
type:
parseGraphQLSchema.parseClassTypes['_User'].classGraphQLCreateType,
},
},
outputFields: {
viewer: {
description:
'This is the new user that was created, signed up and returned as a viewer.',
type: new GraphQLNonNull(parseGraphQLSchema.viewerType),
},
},
mutateAndGetPayload: async (args, context, mutationInfo) => {
try {
const { userFields } = args;
const { config, auth, info } = context;
const { sessionToken } = await objectsMutations.createObject(
'_User',
userFields,
config,
auth,
info
);
info.sessionToken = sessionToken;
return {
viewer: await getUserFromSessionToken(
config,
info,
mutationInfo,
'viewer.user.',
true
),
};
} catch (e) {
parseGraphQLSchema.handleError(e);
}
},
});
parseGraphQLSchema.addGraphQLType(
signUpMutation.args.input.type.ofType,
true,
true
);
parseGraphQLSchema.addGraphQLType(signUpMutation.type, true, true);
parseGraphQLSchema.addGraphQLMutation('signUp', signUpMutation, true, true);
parseGraphQLSchema.addGraphQLMutation(
'logIn',
{
description: 'The logIn mutation can be used to log the user in.',
args: {
fields: {
description: 'This is data needed to login',
type: parseGraphQLSchema.parseClassTypes['_User'].logInInputType,
},
const logInMutation = mutationWithClientMutationId({
name: 'LogIn',
description: 'The logIn mutation can be used to log in an existing user.',
inputFields: {
username: {
description: 'This is the username used to log in the user.',
type: new GraphQLNonNull(GraphQLString),
},
type: new GraphQLNonNull(parseGraphQLSchema.viewerType),
async resolve(_source, args, context) {
try {
const {
fields: { username, password },
} = args;
const { config, auth, info } = context;
return (await usersRouter.handleLogIn({
body: {
username,
password,
},
query: {},
config,
auth,
info,
})).response;
} catch (e) {
parseGraphQLSchema.handleError(e);
}
password: {
description: 'This is the password used to log in the user.',
type: new GraphQLNonNull(GraphQLString),
},
},
outputFields: {
viewer: {
description:
'This is the existing user that was logged in and returned as a viewer.',
type: new GraphQLNonNull(parseGraphQLSchema.viewerType),
},
},
mutateAndGetPayload: async (args, context, mutationInfo) => {
try {
const { username, password } = args;
const { config, auth, info } = context;
const { sessionToken } = (await usersRouter.handleLogIn({
body: {
username,
password,
},
query: {},
config,
auth,
info,
})).response;
info.sessionToken = sessionToken;
return {
viewer: await getUserFromSessionToken(
config,
info,
mutationInfo,
'viewer.user.',
true
),
};
} catch (e) {
parseGraphQLSchema.handleError(e);
}
},
});
parseGraphQLSchema.addGraphQLType(
logInMutation.args.input.type.ofType,
true,
true
);
parseGraphQLSchema.addGraphQLType(logInMutation.type, true, true);
parseGraphQLSchema.addGraphQLMutation('logIn', logInMutation, true, true);
parseGraphQLSchema.addGraphQLMutation(
'logOut',
{
description: 'The logOut mutation can be used to log the user out.',
type: new GraphQLNonNull(parseGraphQLSchema.viewerType),
async resolve(_source, _args, context, mutationInfo) {
try {
const { config, auth, info } = context;
const viewer = await getUserFromSessionToken(
config,
info,
mutationInfo
);
await usersRouter.handleLogOut({
config,
auth,
info,
});
return viewer;
} catch (e) {
parseGraphQLSchema.handleError(e);
}
const logOutMutation = mutationWithClientMutationId({
name: 'LogOut',
description: 'The logOut mutation can be used to log out an existing user.',
outputFields: {
viewer: {
description:
'This is the existing user that was logged out and returned as a viewer.',
type: new GraphQLNonNull(parseGraphQLSchema.viewerType),
},
},
mutateAndGetPayload: async (_args, context, mutationInfo) => {
try {
const { config, auth, info } = context;
const viewer = await getUserFromSessionToken(
config,
info,
mutationInfo,
'viewer.user.',
true
);
await usersRouter.handleLogOut({
config,
auth,
info,
});
return { viewer };
} catch (e) {
parseGraphQLSchema.handleError(e);
}
},
});
parseGraphQLSchema.addGraphQLType(
logOutMutation.args.input.type.ofType,
true,
true
);
parseGraphQLSchema.addGraphQLType(logOutMutation.type, true, true);
parseGraphQLSchema.addGraphQLMutation('logOut', logOutMutation, true, true);
};
export { load };