Files
kami-parse-server/src/GraphQL/loaders/usersMutations.js
Omair Vaiyani d3810c2eba GraphQL Configuration Options (#5782)
* add parse-graph-ql configuration for class schema customisation

Not yet tested - essentially an RFC

* refactor and add graphql router, controller and config cache

* fix(GraphQLController): add missing check isEnabled

* chore(GraphQLController): remove awaits from cache put

* chore(GraphQLController): remove check for if its enabled

* refactor(GraphQLController): only use cache if mounted

* chore(GraphQLController): group all validation errors and throw at once

* chore(GraphQLSchema): move transformations into controller validation

* refactor(GraphQL): improve ctrl validation and fix schema usage of config

* refactor(GraphQLSchema): remove code related to additional schema

This code has been moved into a separate feature branch.

* fix(GraphQLSchema): fix incorrect default return type for class configs

* refactor(GraphQLSchema): update staleness check code to account for config

* fix(GraphQLServer): fix regressed tests due to internal schema changes

This will be followed up with a backwards compatability fix for the `ClassFields` issue to avoid breakages for our users

* refactor: rename to ParseGraphQLController for consistency

* fix(ParseGraphQLCtrl): numerous fixes for validity checking

Also includes some minor code refactoring

* chore(GraphQL): minor syntax cleanup

* fix(SchemaController): add _GraphQLConfig to volatile classes

* refactor(ParseGraphQLServer): return update config value in setGraphQLConfig

* testing(ParseGraphQL): add test cases for new graphQLConfig

* fix(GraphQLController): fix issue where config with multiple items was not being mapped to the db

* fix(postgres): add _GraphQLConfig default schema on load

fixes failing postgres tests

* GraphQL @mock directive (#5836)

* Add mock directive
* Include tests for @mock directive

* Fix existing tests due to the change from ClassFields to ClassCreateFields

* fix(parseClassMutations): safer type transformation based on input type

* fix(parseClassMutations): only define necessary input fields

* fix(GraphQL): fix incorrect import paths
2019-07-25 12:46:25 -07:00

114 lines
2.9 KiB
JavaScript

import {
GraphQLBoolean,
GraphQLNonNull,
GraphQLObjectType,
GraphQLString,
} from 'graphql';
import UsersRouter from '../../Routers/UsersRouter';
import * as defaultGraphQLTypes from './defaultGraphQLTypes';
import * as objectsMutations from './objectsMutations';
const usersRouter = new UsersRouter();
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,
},
},
type: new GraphQLNonNull(defaultGraphQLTypes.SIGN_UP_RESULT),
async resolve(_source, args, context) {
try {
const { fields } = args;
const { config, auth, info } = context;
return await objectsMutations.createObject(
'_User',
fields,
config,
auth,
info
);
} catch (e) {
parseGraphQLSchema.handleError(e);
}
},
};
fields.logIn = {
description: 'The logIn mutation can be used to log the user in.',
args: {
username: {
description: 'This is the username used to log the user in.',
type: new GraphQLNonNull(GraphQLString),
},
password: {
description: 'This is the password used to log the user in.',
type: new GraphQLNonNull(GraphQLString),
},
},
type: new GraphQLNonNull(parseGraphQLSchema.meType),
async resolve(_source, args, context) {
try {
const { 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);
}
},
};
fields.logOut = {
description: 'The logOut mutation can be used to log the user out.',
type: new GraphQLNonNull(GraphQLBoolean),
async resolve(_source, _args, context) {
try {
const { config, auth, info } = context;
await usersRouter.handleLogOut({
config,
auth,
info,
});
return true;
} catch (e) {
parseGraphQLSchema.handleError(e);
}
},
};
const usersMutation = new GraphQLObjectType({
name: 'UsersMutation',
description: 'UsersMutation is the top level type for files mutations.',
fields,
});
parseGraphQLSchema.graphQLTypes.push(usersMutation);
parseGraphQLSchema.graphQLMutations.users = {
description: 'This is the top level for users mutations.',
type: usersMutation,
resolve: () => new Object(),
};
};
export { load };