Skip to content

Commit 0288ebb

Browse files
committed
Client mutation id on logOut mutation
1 parent 9d689f1 commit 0288ebb

File tree

3 files changed

+87
-29
lines changed

3 files changed

+87
-29
lines changed

spec/ParseGraphQLServer.spec.js

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,42 @@ describe('ParseGraphQLServer', () => {
943943

944944
expect(payloadFields).toEqual(['clientMutationId', 'viewer']);
945945
});
946+
947+
it('should have clientMutationId in log out mutation input', async () => {
948+
const inputFields = (await apolloClient.query({
949+
query: gql`
950+
query {
951+
__type(name: "LogOutInput") {
952+
inputFields {
953+
name
954+
}
955+
}
956+
}
957+
`,
958+
})).data['__type'].inputFields
959+
.map(field => field.name)
960+
.sort();
961+
962+
expect(inputFields).toEqual(['clientMutationId']);
963+
});
964+
965+
it('should have clientMutationId in log out mutation payload', async () => {
966+
const payloadFields = (await apolloClient.query({
967+
query: gql`
968+
query {
969+
__type(name: "LogOutPayload") {
970+
fields {
971+
name
972+
}
973+
}
974+
}
975+
`,
976+
})).data['__type'].fields
977+
.map(field => field.name)
978+
.sort();
979+
980+
expect(payloadFields).toEqual(['clientMutationId', 'viewer']);
981+
});
946982
});
947983

948984
describe('Parse Class Types', () => {
@@ -5902,6 +5938,7 @@ describe('ParseGraphQLServer', () => {
59025938
});
59035939

59045940
it('should log the user out', async () => {
5941+
const clientMutationId = uuidv4();
59055942
const user = new Parse.User();
59065943
user.setUsername('user1');
59075944
user.setPassword('user1');
@@ -5930,9 +5967,12 @@ describe('ParseGraphQLServer', () => {
59305967

59315968
const logOut = await apolloClient.mutate({
59325969
mutation: gql`
5933-
mutation LogOutUser {
5934-
logOut {
5935-
sessionToken
5970+
mutation LogOutUser($input: LogOutInput!) {
5971+
logOut(input: $input) {
5972+
clientMutationId
5973+
viewer {
5974+
sessionToken
5975+
}
59365976
}
59375977
}
59385978
`,
@@ -5941,8 +5981,14 @@ describe('ParseGraphQLServer', () => {
59415981
'X-Parse-Session-Token': sessionToken,
59425982
},
59435983
},
5984+
variables: {
5985+
input: {
5986+
clientMutationId,
5987+
},
5988+
},
59445989
});
5945-
expect(logOut.data.logOut).toBeDefined();
5990+
expect(logOut.data.logOut.clientMutationId).toEqual(clientMutationId);
5991+
expect(logOut.data.logOut.viewer.sessionToken).toEqual(sessionToken);
59465992

59475993
try {
59485994
await apolloClient.query({

src/GraphQL/ParseGraphQLSchema.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const RESERVED_GRAPHQL_TYPE_NAMES = [
4040
'SignUpPayload',
4141
'LogInInput',
4242
'LogInPayload',
43+
'LogOutInput',
44+
'LogOutPayload',
4345
'CloudCodeFunction',
4446
'CallCloudCodeInput',
4547
'CallCloudCodePayload',

src/GraphQL/loaders/usersMutations.js

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -117,36 +117,46 @@ const load = parseGraphQLSchema => {
117117
parseGraphQLSchema.addGraphQLType(logInMutation.type, true, true);
118118
parseGraphQLSchema.addGraphQLMutation('logIn', logInMutation, true, true);
119119

120-
parseGraphQLSchema.addGraphQLMutation(
121-
'logOut',
122-
{
123-
description: 'The logOut mutation can be used to log the user out.',
124-
type: new GraphQLNonNull(parseGraphQLSchema.viewerType),
125-
async resolve(_source, _args, context, mutationInfo) {
126-
try {
127-
const { config, auth, info } = context;
128-
129-
const viewer = await getUserFromSessionToken(
130-
config,
131-
info,
132-
mutationInfo
133-
);
134-
135-
await usersRouter.handleLogOut({
136-
config,
137-
auth,
138-
info,
139-
});
140-
141-
return viewer;
142-
} catch (e) {
143-
parseGraphQLSchema.handleError(e);
144-
}
120+
const logOutMutation = mutationWithClientMutationId({
121+
name: 'LogOut',
122+
description: 'The logOut mutation can be used to log out an existing user.',
123+
outputFields: {
124+
viewer: {
125+
description:
126+
'This is the existing user that was logged out and returned as a viewer.',
127+
type: new GraphQLNonNull(parseGraphQLSchema.viewerType),
145128
},
146129
},
130+
mutateAndGetPayload: async (_args, context, mutationInfo) => {
131+
try {
132+
const { config, auth, info } = context;
133+
134+
const viewer = await getUserFromSessionToken(
135+
config,
136+
info,
137+
mutationInfo
138+
);
139+
140+
await usersRouter.handleLogOut({
141+
config,
142+
auth,
143+
info,
144+
});
145+
146+
return { viewer };
147+
} catch (e) {
148+
parseGraphQLSchema.handleError(e);
149+
}
150+
},
151+
});
152+
153+
parseGraphQLSchema.addGraphQLType(
154+
logOutMutation.args.input.type.ofType,
147155
true,
148156
true
149157
);
158+
parseGraphQLSchema.addGraphQLType(logOutMutation.type, true, true);
159+
parseGraphQLSchema.addGraphQLMutation('logOut', logOutMutation, true, true);
150160
};
151161

152162
export { load };

0 commit comments

Comments
 (0)