Skip to content

Commit ab8a49a

Browse files
committed
Client mutation id on delete object mutation
1 parent e9fe1c5 commit ab8a49a

File tree

2 files changed

+244
-52
lines changed

2 files changed

+244
-52
lines changed

spec/ParseGraphQLServer.spec.js

Lines changed: 208 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,108 @@ describe('ParseGraphQLServer', () => {
11471147
'someClass',
11481148
]);
11491149
});
1150+
1151+
it('should have clientMutationId in custom update object mutation input', async () => {
1152+
const obj = new Parse.Object('SomeClass');
1153+
await obj.save();
1154+
1155+
await parseGraphQLServer.parseGraphQLSchema.databaseController.schemaCache.clear();
1156+
1157+
const createObjectInputFields = (await apolloClient.query({
1158+
query: gql`
1159+
query {
1160+
__type(name: "UpdateSomeClassInput") {
1161+
inputFields {
1162+
name
1163+
}
1164+
}
1165+
}
1166+
`,
1167+
})).data['__type'].inputFields
1168+
.map(field => field.name)
1169+
.sort();
1170+
1171+
expect(createObjectInputFields).toEqual([
1172+
'clientMutationId',
1173+
'fields',
1174+
'id',
1175+
]);
1176+
});
1177+
1178+
it('should have clientMutationId in custom update object mutation payload', async () => {
1179+
const obj = new Parse.Object('SomeClass');
1180+
await obj.save();
1181+
1182+
await parseGraphQLServer.parseGraphQLSchema.databaseController.schemaCache.clear();
1183+
1184+
const createObjectPayloadFields = (await apolloClient.query({
1185+
query: gql`
1186+
query {
1187+
__type(name: "UpdateSomeClassPayload") {
1188+
fields {
1189+
name
1190+
}
1191+
}
1192+
}
1193+
`,
1194+
})).data['__type'].fields
1195+
.map(field => field.name)
1196+
.sort();
1197+
1198+
expect(createObjectPayloadFields).toEqual([
1199+
'clientMutationId',
1200+
'someClass',
1201+
]);
1202+
});
1203+
1204+
it('should have clientMutationId in custom delete object mutation input', async () => {
1205+
const obj = new Parse.Object('SomeClass');
1206+
await obj.save();
1207+
1208+
await parseGraphQLServer.parseGraphQLSchema.databaseController.schemaCache.clear();
1209+
1210+
const createObjectInputFields = (await apolloClient.query({
1211+
query: gql`
1212+
query {
1213+
__type(name: "DeleteSomeClassInput") {
1214+
inputFields {
1215+
name
1216+
}
1217+
}
1218+
}
1219+
`,
1220+
})).data['__type'].inputFields
1221+
.map(field => field.name)
1222+
.sort();
1223+
1224+
expect(createObjectInputFields).toEqual(['clientMutationId', 'id']);
1225+
});
1226+
1227+
it('should have clientMutationId in custom delete object mutation payload', async () => {
1228+
const obj = new Parse.Object('SomeClass');
1229+
await obj.save();
1230+
1231+
await parseGraphQLServer.parseGraphQLSchema.databaseController.schemaCache.clear();
1232+
1233+
const createObjectPayloadFields = (await apolloClient.query({
1234+
query: gql`
1235+
query {
1236+
__type(name: "DeleteSomeClassPayload") {
1237+
fields {
1238+
name
1239+
}
1240+
}
1241+
}
1242+
`,
1243+
})).data['__type'].fields
1244+
.map(field => field.name)
1245+
.sort();
1246+
1247+
expect(createObjectPayloadFields).toEqual([
1248+
'clientMutationId',
1249+
'someClass',
1250+
]);
1251+
});
11501252
});
11511253

11521254
describe('Parse Class Types', () => {
@@ -1444,8 +1546,8 @@ describe('ParseGraphQLServer', () => {
14441546
apolloClient.query({
14451547
query: gql`
14461548
mutation DeleteCustomer($id: ID!) {
1447-
deleteCustomer(id: $id) {
1448-
id
1549+
deleteCustomer(input: { id: $id }) {
1550+
clientMutationId
14491551
}
14501552
}
14511553
`,
@@ -1532,8 +1634,8 @@ describe('ParseGraphQLServer', () => {
15321634
apolloClient.query({
15331635
query: gql`
15341636
mutation DeleteSuperCar($id: ID!) {
1535-
deleteSuperCar(id: $id) {
1536-
id
1637+
deleteSuperCar(input: { id: $id }) {
1638+
clientMutationId
15371639
}
15381640
}
15391641
`,
@@ -1578,7 +1680,9 @@ describe('ParseGraphQLServer', () => {
15781680
apolloClient.query({
15791681
query: gql`
15801682
mutation DeleteCustomer($id: ID!, $foo: String!) {
1581-
deleteCustomer(id: $id)
1683+
deleteCustomer(input: { id: $id }) {
1684+
clientMutationId
1685+
}
15821686
}
15831687
`,
15841688
variables: {
@@ -2355,20 +2459,36 @@ describe('ParseGraphQLServer', () => {
23552459
$id5: ID!
23562460
$id6: ID!
23572461
) {
2358-
secondaryObject1: deleteSecondaryObject(id: $id1) {
2359-
id
2360-
objectId
2361-
someField
2462+
secondaryObject1: deleteSecondaryObject(
2463+
input: { id: $id1 }
2464+
) {
2465+
secondaryObject {
2466+
id
2467+
objectId
2468+
someField
2469+
}
23622470
}
2363-
secondaryObject3: deleteSecondaryObject(id: $id3) {
2364-
objectId
2365-
someField
2471+
secondaryObject3: deleteSecondaryObject(
2472+
input: { id: $id3 }
2473+
) {
2474+
secondaryObject {
2475+
objectId
2476+
someField
2477+
}
23662478
}
2367-
secondaryObject5: deleteSecondaryObject(id: $id5) {
2368-
id
2479+
secondaryObject5: deleteSecondaryObject(
2480+
input: { id: $id5 }
2481+
) {
2482+
secondaryObject {
2483+
id
2484+
}
23692485
}
2370-
secondaryObject6: deleteSecondaryObject(id: $id6) {
2371-
objectId
2486+
secondaryObject6: deleteSecondaryObject(
2487+
input: { id: $id6 }
2488+
) {
2489+
secondaryObject {
2490+
objectId
2491+
}
23722492
}
23732493
}
23742494
`,
@@ -2466,14 +2586,19 @@ describe('ParseGraphQLServer', () => {
24662586
`,
24672587
variables: {
24682588
id1:
2469-
deleteSecondaryObjectsResult.data.secondaryObject1.objectId,
2589+
deleteSecondaryObjectsResult.data.secondaryObject1
2590+
.secondaryObject.objectId,
24702591
id2: getSecondaryObjectsResult.data.secondaryObject2.id,
24712592
id3:
2472-
deleteSecondaryObjectsResult.data.secondaryObject3.objectId,
2593+
deleteSecondaryObjectsResult.data.secondaryObject3
2594+
.secondaryObject.objectId,
24732595
id4: getSecondaryObjectsResult.data.secondaryObject4.objectId,
2474-
id5: deleteSecondaryObjectsResult.data.secondaryObject5.id,
2596+
id5:
2597+
deleteSecondaryObjectsResult.data.secondaryObject5
2598+
.secondaryObject.id,
24752599
id6:
2476-
deleteSecondaryObjectsResult.data.secondaryObject6.objectId,
2600+
deleteSecondaryObjectsResult.data.secondaryObject6
2601+
.secondaryObject.objectId,
24772602
},
24782603
context: {
24792604
headers: {
@@ -5951,6 +6076,7 @@ describe('ParseGraphQLServer', () => {
59516076

59526077
describe('Delete', () => {
59536078
it('should return a specific type using class specific mutation', async () => {
6079+
const clientMutationId = uuidv4();
59546080
const obj = new Parse.Object('Customer');
59556081
obj.set('someField1', 'someField1Value1');
59566082
obj.set('someField2', 'someField2Value1');
@@ -5960,25 +6086,36 @@ describe('ParseGraphQLServer', () => {
59606086

59616087
const result = await apolloClient.mutate({
59626088
mutation: gql`
5963-
mutation DeleteCustomer($id: ID!) {
5964-
deleteCustomer(id: $id) {
5965-
id
5966-
objectId
5967-
someField1
5968-
someField2
6089+
mutation DeleteCustomer($input: DeleteCustomerInput!) {
6090+
deleteCustomer(input: $input) {
6091+
clientMutationId
6092+
customer {
6093+
id
6094+
objectId
6095+
someField1
6096+
someField2
6097+
}
59696098
}
59706099
}
59716100
`,
59726101
variables: {
5973-
id: obj.id,
6102+
input: {
6103+
clientMutationId,
6104+
id: obj.id,
6105+
},
59746106
},
59756107
});
59766108

5977-
expect(result.data.deleteCustomer.objectId).toEqual(obj.id);
5978-
expect(result.data.deleteCustomer.someField1).toEqual(
6109+
expect(result.data.deleteCustomer.clientMutationId).toEqual(
6110+
clientMutationId
6111+
);
6112+
expect(result.data.deleteCustomer.customer.objectId).toEqual(
6113+
obj.id
6114+
);
6115+
expect(result.data.deleteCustomer.customer.someField1).toEqual(
59796116
'someField1Value1'
59806117
);
5981-
expect(result.data.deleteCustomer.someField2).toEqual(
6118+
expect(result.data.deleteCustomer.customer.someField2).toEqual(
59826119
'someField2Value1'
59836120
);
59846121

@@ -5998,8 +6135,11 @@ describe('ParseGraphQLServer', () => {
59986135
mutation DeleteSomeObject(
59996136
$id: ID!
60006137
) {
6001-
delete: delete${className}(id: $id) {
6002-
objectId
6138+
delete: delete${className}(input: { id: $id }) {
6139+
${className.charAt(0).toLowerCase() +
6140+
className.slice(1)} {
6141+
objectId
6142+
}
60036143
}
60046144
}
60056145
`,
@@ -6035,31 +6175,43 @@ describe('ParseGraphQLServer', () => {
60356175
})
60366176
);
60376177
expect(
6038-
(await deleteObject(object4.className, object4.id)).data.delete
6178+
(await deleteObject(object4.className, object4.id)).data.delete[
6179+
object4.className.charAt(0).toLowerCase() +
6180+
object4.className.slice(1)
6181+
]
60396182
).toEqual({ objectId: object4.id, __typename: 'PublicClass' });
60406183
await expectAsync(
60416184
object4.fetch({ useMasterKey: true })
60426185
).toBeRejectedWith(jasmine.stringMatching('Object not found'));
60436186
expect(
60446187
(await deleteObject(object1.className, object1.id, {
60456188
'X-Parse-Master-Key': 'test',
6046-
})).data.delete
6189+
})).data.delete[
6190+
object1.className.charAt(0).toLowerCase() +
6191+
object1.className.slice(1)
6192+
]
60476193
).toEqual({ objectId: object1.id, __typename: 'GraphQLClass' });
60486194
await expectAsync(
60496195
object1.fetch({ useMasterKey: true })
60506196
).toBeRejectedWith(jasmine.stringMatching('Object not found'));
60516197
expect(
60526198
(await deleteObject(object2.className, object2.id, {
60536199
'X-Parse-Session-Token': user2.getSessionToken(),
6054-
})).data.delete
6200+
})).data.delete[
6201+
object2.className.charAt(0).toLowerCase() +
6202+
object2.className.slice(1)
6203+
]
60556204
).toEqual({ objectId: object2.id, __typename: 'GraphQLClass' });
60566205
await expectAsync(
60576206
object2.fetch({ useMasterKey: true })
60586207
).toBeRejectedWith(jasmine.stringMatching('Object not found'));
60596208
expect(
60606209
(await deleteObject(object3.className, object3.id, {
60616210
'X-Parse-Session-Token': user5.getSessionToken(),
6062-
})).data.delete
6211+
})).data.delete[
6212+
object3.className.charAt(0).toLowerCase() +
6213+
object3.className.slice(1)
6214+
]
60636215
).toEqual({ objectId: object3.id, __typename: 'GraphQLClass' });
60646216
await expectAsync(
60656217
object3.fetch({ useMasterKey: true })
@@ -6077,8 +6229,11 @@ describe('ParseGraphQLServer', () => {
60776229
mutation DeleteSomeObject(
60786230
$id: ID!
60796231
) {
6080-
delete${className}(id: $id) {
6081-
objectId
6232+
delete${className}(input: { id: $id }) {
6233+
${className.charAt(0).toLowerCase() +
6234+
className.slice(1)} {
6235+
objectId
6236+
}
60826237
}
60836238
}
60846239
`,
@@ -6116,6 +6271,9 @@ describe('ParseGraphQLServer', () => {
61166271
expect(
61176272
(await deleteObject(object4.className, object4.id)).data[
61186273
`delete${object4.className}`
6274+
][
6275+
object4.className.charAt(0).toLowerCase() +
6276+
object4.className.slice(1)
61196277
].objectId
61206278
).toEqual(object4.id);
61216279
await expectAsync(
@@ -6124,23 +6282,32 @@ describe('ParseGraphQLServer', () => {
61246282
expect(
61256283
(await deleteObject(object1.className, object1.id, {
61266284
'X-Parse-Master-Key': 'test',
6127-
})).data[`delete${object1.className}`].objectId
6285+
})).data[`delete${object1.className}`][
6286+
object1.className.charAt(0).toLowerCase() +
6287+
object1.className.slice(1)
6288+
].objectId
61286289
).toEqual(object1.id);
61296290
await expectAsync(
61306291
object1.fetch({ useMasterKey: true })
61316292
).toBeRejectedWith(jasmine.stringMatching('Object not found'));
61326293
expect(
61336294
(await deleteObject(object2.className, object2.id, {
61346295
'X-Parse-Session-Token': user2.getSessionToken(),
6135-
})).data[`delete${object2.className}`].objectId
6296+
})).data[`delete${object2.className}`][
6297+
object2.className.charAt(0).toLowerCase() +
6298+
object2.className.slice(1)
6299+
].objectId
61366300
).toEqual(object2.id);
61376301
await expectAsync(
61386302
object2.fetch({ useMasterKey: true })
61396303
).toBeRejectedWith(jasmine.stringMatching('Object not found'));
61406304
expect(
61416305
(await deleteObject(object3.className, object3.id, {
61426306
'X-Parse-Session-Token': user5.getSessionToken(),
6143-
})).data[`delete${object3.className}`].objectId
6307+
})).data[`delete${object3.className}`][
6308+
object3.className.charAt(0).toLowerCase() +
6309+
object3.className.slice(1)
6310+
].objectId
61446311
).toEqual(object3.id);
61456312
await expectAsync(
61466313
object3.fetch({ useMasterKey: true })

0 commit comments

Comments
 (0)