Remove nested operations from GraphQL API (#5931)
* Remove nested operations * Improve error log * Fix bug schema to load * Fix ParseGraphQLSchema tests * Fix tests * Fix failing tests * Rename call to callCloudCode
This commit is contained in:
committed by
Antoine Cormouls
parent
47d1a74ac0
commit
ee5aeeaff5
@@ -1,4 +1,4 @@
|
||||
import { GraphQLNonNull, GraphQLObjectType } from 'graphql';
|
||||
import { GraphQLNonNull } from 'graphql';
|
||||
import UsersRouter from '../../Routers/UsersRouter';
|
||||
import * as objectsMutations from './objectsMutations';
|
||||
import { getUserFromSessionToken } from './usersQueries';
|
||||
@@ -9,110 +9,111 @@ const load = parseGraphQLSchema => {
|
||||
if (parseGraphQLSchema.isUsersClassDisabled) {
|
||||
return;
|
||||
}
|
||||
const fields = {};
|
||||
|
||||
fields.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,
|
||||
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);
|
||||
}
|
||||
},
|
||||
},
|
||||
type: new GraphQLNonNull(parseGraphQLSchema.viewerType),
|
||||
async resolve(_source, args, context, mutationInfo) {
|
||||
try {
|
||||
const { fields } = args;
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
const { config, auth, info } = context;
|
||||
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,
|
||||
},
|
||||
},
|
||||
type: new GraphQLNonNull(parseGraphQLSchema.viewerType),
|
||||
async resolve(_source, args, context) {
|
||||
try {
|
||||
const {
|
||||
fields: { username, password },
|
||||
} = 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);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
fields.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,
|
||||
return (await usersRouter.handleLogIn({
|
||||
body: {
|
||||
username,
|
||||
password,
|
||||
},
|
||||
query: {},
|
||||
config,
|
||||
auth,
|
||||
info,
|
||||
})).response;
|
||||
} catch (e) {
|
||||
parseGraphQLSchema.handleError(e);
|
||||
}
|
||||
},
|
||||
},
|
||||
type: new GraphQLNonNull(parseGraphQLSchema.viewerType),
|
||||
async resolve(_source, args, context) {
|
||||
try {
|
||||
const {
|
||||
fields: { username, password },
|
||||
} = args;
|
||||
const { config, auth, info } = context;
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
return (await usersRouter.handleLogIn({
|
||||
body: {
|
||||
username,
|
||||
password,
|
||||
},
|
||||
query: {},
|
||||
config,
|
||||
auth,
|
||||
info,
|
||||
})).response;
|
||||
} catch (e) {
|
||||
parseGraphQLSchema.handleError(e);
|
||||
}
|
||||
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);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
fields.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 usersMutation = new GraphQLObjectType({
|
||||
name: 'UsersMutation',
|
||||
description: 'UsersMutation is the top level type for files mutations.',
|
||||
fields,
|
||||
});
|
||||
parseGraphQLSchema.addGraphQLType(usersMutation, true, true);
|
||||
|
||||
parseGraphQLSchema.graphQLMutations.users = {
|
||||
description: 'This is the top level for users mutations.',
|
||||
type: usersMutation,
|
||||
resolve: () => new Object(),
|
||||
};
|
||||
true,
|
||||
true
|
||||
);
|
||||
};
|
||||
|
||||
export { load };
|
||||
|
||||
Reference in New Issue
Block a user