Remove viewer from logout (#7029)
This commit is contained in:
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLString,
|
||||
GraphQLBoolean,
|
||||
GraphQLInputObjectType,
|
||||
} from 'graphql';
|
||||
import { GraphQLNonNull, GraphQLString, GraphQLBoolean, GraphQLInputObjectType } from 'graphql';
|
||||
import { mutationWithClientMutationId } from 'graphql-relay';
|
||||
import UsersRouter from '../../Routers/UsersRouter';
|
||||
import * as objectsMutations from '../helpers/objectsMutations';
|
||||
@@ -20,20 +15,16 @@ const load = parseGraphQLSchema => {
|
||||
|
||||
const signUpMutation = mutationWithClientMutationId({
|
||||
name: 'SignUp',
|
||||
description:
|
||||
'The signUp mutation can be used to create and sign up a new user.',
|
||||
description: 'The signUp mutation can be used to create and sign up a new user.',
|
||||
inputFields: {
|
||||
fields: {
|
||||
descriptions:
|
||||
'These are the fields of the new user to be created and signed up.',
|
||||
type:
|
||||
parseGraphQLSchema.parseClassTypes['_User'].classGraphQLCreateType,
|
||||
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.',
|
||||
description: 'This is the new user that was created, signed up and returned as a viewer.',
|
||||
type: new GraphQLNonNull(parseGraphQLSchema.viewerType),
|
||||
},
|
||||
},
|
||||
@@ -59,12 +50,7 @@ const load = parseGraphQLSchema => {
|
||||
context.info.sessionToken = sessionToken;
|
||||
|
||||
return {
|
||||
viewer: await getUserFromSessionToken(
|
||||
context,
|
||||
mutationInfo,
|
||||
'viewer.user.',
|
||||
objectId
|
||||
),
|
||||
viewer: await getUserFromSessionToken(context, mutationInfo, 'viewer.user.', objectId),
|
||||
};
|
||||
} catch (e) {
|
||||
parseGraphQLSchema.handleError(e);
|
||||
@@ -72,11 +58,7 @@ const load = parseGraphQLSchema => {
|
||||
},
|
||||
});
|
||||
|
||||
parseGraphQLSchema.addGraphQLType(
|
||||
signUpMutation.args.input.type.ofType,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLType(signUpMutation.args.input.type.ofType, true, true);
|
||||
parseGraphQLSchema.addGraphQLType(signUpMutation.type, true, true);
|
||||
parseGraphQLSchema.addGraphQLMutation('signUp', signUpMutation, true, true);
|
||||
const logInWithMutation = mutationWithClientMutationId({
|
||||
@@ -89,35 +71,30 @@ const load = parseGraphQLSchema => {
|
||||
type: new GraphQLNonNull(OBJECT),
|
||||
},
|
||||
fields: {
|
||||
descriptions:
|
||||
'These are the fields of the user to be created/updated and logged in.',
|
||||
descriptions: 'These are the fields of the user to be created/updated and logged in.',
|
||||
type: new GraphQLInputObjectType({
|
||||
name: 'UserLoginWithInput',
|
||||
fields: () => {
|
||||
const classGraphQLCreateFields = parseGraphQLSchema.parseClassTypes[
|
||||
'_User'
|
||||
].classGraphQLCreateType.getFields();
|
||||
return Object.keys(classGraphQLCreateFields).reduce(
|
||||
(fields, fieldName) => {
|
||||
if (
|
||||
fieldName !== 'password' &&
|
||||
fieldName !== 'username' &&
|
||||
fieldName !== 'authData'
|
||||
) {
|
||||
fields[fieldName] = classGraphQLCreateFields[fieldName];
|
||||
}
|
||||
return fields;
|
||||
},
|
||||
{}
|
||||
);
|
||||
return Object.keys(classGraphQLCreateFields).reduce((fields, fieldName) => {
|
||||
if (
|
||||
fieldName !== 'password' &&
|
||||
fieldName !== 'username' &&
|
||||
fieldName !== 'authData'
|
||||
) {
|
||||
fields[fieldName] = classGraphQLCreateFields[fieldName];
|
||||
}
|
||||
return fields;
|
||||
}, {});
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
outputFields: {
|
||||
viewer: {
|
||||
description:
|
||||
'This is the new user that was created, signed up and returned as a viewer.',
|
||||
description: 'This is the new user that was created, signed up and returned as a viewer.',
|
||||
type: new GraphQLNonNull(parseGraphQLSchema.viewerType),
|
||||
},
|
||||
},
|
||||
@@ -143,12 +120,7 @@ const load = parseGraphQLSchema => {
|
||||
context.info.sessionToken = sessionToken;
|
||||
|
||||
return {
|
||||
viewer: await getUserFromSessionToken(
|
||||
context,
|
||||
mutationInfo,
|
||||
'viewer.user.',
|
||||
objectId
|
||||
),
|
||||
viewer: await getUserFromSessionToken(context, mutationInfo, 'viewer.user.', objectId),
|
||||
};
|
||||
} catch (e) {
|
||||
parseGraphQLSchema.handleError(e);
|
||||
@@ -156,18 +128,9 @@ const load = parseGraphQLSchema => {
|
||||
},
|
||||
});
|
||||
|
||||
parseGraphQLSchema.addGraphQLType(
|
||||
logInWithMutation.args.input.type.ofType,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLType(logInWithMutation.args.input.type.ofType, true, true);
|
||||
parseGraphQLSchema.addGraphQLType(logInWithMutation.type, true, true);
|
||||
parseGraphQLSchema.addGraphQLMutation(
|
||||
'logInWith',
|
||||
logInWithMutation,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLMutation('logInWith', logInWithMutation, true, true);
|
||||
|
||||
const logInMutation = mutationWithClientMutationId({
|
||||
name: 'LogIn',
|
||||
@@ -184,8 +147,7 @@ const load = parseGraphQLSchema => {
|
||||
},
|
||||
outputFields: {
|
||||
viewer: {
|
||||
description:
|
||||
'This is the existing user that was logged in and returned as a viewer.',
|
||||
description: 'This is the existing user that was logged in and returned as a viewer.',
|
||||
type: new GraphQLNonNull(parseGraphQLSchema.viewerType),
|
||||
},
|
||||
},
|
||||
@@ -210,12 +172,7 @@ const load = parseGraphQLSchema => {
|
||||
context.info.sessionToken = sessionToken;
|
||||
|
||||
return {
|
||||
viewer: await getUserFromSessionToken(
|
||||
context,
|
||||
mutationInfo,
|
||||
'viewer.user.',
|
||||
objectId
|
||||
),
|
||||
viewer: await getUserFromSessionToken(context, mutationInfo, 'viewer.user.', objectId),
|
||||
};
|
||||
} catch (e) {
|
||||
parseGraphQLSchema.handleError(e);
|
||||
@@ -223,11 +180,7 @@ const load = parseGraphQLSchema => {
|
||||
},
|
||||
});
|
||||
|
||||
parseGraphQLSchema.addGraphQLType(
|
||||
logInMutation.args.input.type.ofType,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLType(logInMutation.args.input.type.ofType, true, true);
|
||||
parseGraphQLSchema.addGraphQLType(logInMutation.type, true, true);
|
||||
parseGraphQLSchema.addGraphQLMutation('logIn', logInMutation, true, true);
|
||||
|
||||
@@ -235,41 +188,29 @@ const load = parseGraphQLSchema => {
|
||||
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),
|
||||
ok: {
|
||||
description: "It's always true.",
|
||||
type: new GraphQLNonNull(GraphQLBoolean),
|
||||
},
|
||||
},
|
||||
mutateAndGetPayload: async (_args, context, mutationInfo) => {
|
||||
mutateAndGetPayload: async (_args, context) => {
|
||||
try {
|
||||
const { config, auth, info } = context;
|
||||
|
||||
const viewer = await getUserFromSessionToken(
|
||||
context,
|
||||
mutationInfo,
|
||||
'viewer.user.',
|
||||
auth.user.id
|
||||
);
|
||||
|
||||
await usersRouter.handleLogOut({
|
||||
config,
|
||||
auth,
|
||||
info,
|
||||
});
|
||||
|
||||
return { viewer };
|
||||
return { ok: true };
|
||||
} catch (e) {
|
||||
parseGraphQLSchema.handleError(e);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
parseGraphQLSchema.addGraphQLType(
|
||||
logOutMutation.args.input.type.ofType,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLType(logOutMutation.args.input.type.ofType, true, true);
|
||||
parseGraphQLSchema.addGraphQLType(logOutMutation.type, true, true);
|
||||
parseGraphQLSchema.addGraphQLMutation('logOut', logOutMutation, true, true);
|
||||
|
||||
@@ -305,18 +246,9 @@ const load = parseGraphQLSchema => {
|
||||
},
|
||||
});
|
||||
|
||||
parseGraphQLSchema.addGraphQLType(
|
||||
resetPasswordMutation.args.input.type.ofType,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLType(resetPasswordMutation.args.input.type.ofType, true, true);
|
||||
parseGraphQLSchema.addGraphQLType(resetPasswordMutation.type, true, true);
|
||||
parseGraphQLSchema.addGraphQLMutation(
|
||||
'resetPassword',
|
||||
resetPasswordMutation,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLMutation('resetPassword', resetPasswordMutation, true, true);
|
||||
|
||||
const sendVerificationEmailMutation = mutationWithClientMutationId({
|
||||
name: 'SendVerificationEmail',
|
||||
@@ -324,8 +256,7 @@ const load = parseGraphQLSchema => {
|
||||
'The sendVerificationEmail mutation can be used to send the verification email again.',
|
||||
inputFields: {
|
||||
email: {
|
||||
descriptions:
|
||||
'Email of the user that should receive the verification email',
|
||||
descriptions: 'Email of the user that should receive the verification email',
|
||||
type: new GraphQLNonNull(GraphQLString),
|
||||
},
|
||||
},
|
||||
@@ -360,11 +291,7 @@ const load = parseGraphQLSchema => {
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLType(
|
||||
sendVerificationEmailMutation.type,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLType(sendVerificationEmailMutation.type, true, true);
|
||||
parseGraphQLSchema.addGraphQLMutation(
|
||||
'sendVerificationEmail',
|
||||
sendVerificationEmailMutation,
|
||||
|
||||
Reference in New Issue
Block a user