Skip to content

Commit 757fb0b

Browse files
davimacedoMoumouls
authored andcommitted
Remove nested operations from GraphQL API (parse-community#5931)
* Remove nested operations * Improve error log * Fix bug schema to load * Fix ParseGraphQLSchema tests * Fix tests * Fix failing tests * Rename call to callCloudCode
1 parent dbe38bf commit 757fb0b

14 files changed

+1155
-1617
lines changed

spec/ParseGraphQLSchema.spec.js

Lines changed: 64 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ describe('ParseGraphQLSchema', () => {
211211
});
212212
});
213213

214-
describe('addGraphQLObjectQuery', () => {
214+
describe('addGraphQLQuery', () => {
215215
it('should not load and warn duplicated queries', async () => {
216216
let logged = false;
217217
const parseGraphQLSchema = new ParseGraphQLSchema({
@@ -221,21 +221,19 @@ describe('ParseGraphQLSchema', () => {
221221
warn: message => {
222222
logged = true;
223223
expect(message).toEqual(
224-
'Object query someClasses could not be added to the auto schema because it collided with an existing field.'
224+
'Query someClasses could not be added to the auto schema because it collided with an existing field.'
225225
);
226226
},
227227
},
228228
});
229229
await parseGraphQLSchema.load();
230230
const field = {};
231-
expect(
232-
parseGraphQLSchema.addGraphQLObjectQuery('someClasses', field)
233-
).toBe(field);
234-
expect(parseGraphQLSchema.graphQLObjectsQueries['someClasses']).toBe(
231+
expect(parseGraphQLSchema.addGraphQLQuery('someClasses', field)).toBe(
235232
field
236233
);
234+
expect(parseGraphQLSchema.graphQLQueries['someClasses']).toBe(field);
237235
expect(
238-
parseGraphQLSchema.addGraphQLObjectQuery('someClasses', {})
236+
parseGraphQLSchema.addGraphQLQuery('someClasses', {})
239237
).toBeUndefined();
240238
expect(logged).toBeTruthy();
241239
});
@@ -252,16 +250,14 @@ describe('ParseGraphQLSchema', () => {
252250
});
253251
await parseGraphQLSchema.load();
254252
const field = {};
255-
expect(
256-
parseGraphQLSchema.addGraphQLObjectQuery('someClasses', field)
257-
).toBe(field);
258-
expect(parseGraphQLSchema.graphQLObjectsQueries['someClasses']).toBe(
253+
expect(parseGraphQLSchema.addGraphQLQuery('someClasses', field)).toBe(
259254
field
260255
);
256+
expect(parseGraphQLSchema.graphQLQueries['someClasses']).toBe(field);
261257
expect(() =>
262-
parseGraphQLSchema.addGraphQLObjectQuery('someClasses', {}, true)
258+
parseGraphQLSchema.addGraphQLQuery('someClasses', {}, true)
263259
).toThrowError(
264-
'Object query someClasses could not be added to the auto schema because it collided with an existing field.'
260+
'Query someClasses could not be added to the auto schema because it collided with an existing field.'
265261
);
266262
});
267263

@@ -274,15 +270,13 @@ describe('ParseGraphQLSchema', () => {
274270
warn: message => {
275271
logged = true;
276272
expect(message).toEqual(
277-
'Object query get could not be added to the auto schema because it collided with an existing field.'
273+
'Query get could not be added to the auto schema because it collided with an existing field.'
278274
);
279275
},
280276
},
281277
});
282278
await parseGraphQLSchema.load();
283-
expect(
284-
parseGraphQLSchema.addGraphQLObjectQuery('get', {})
285-
).toBeUndefined();
279+
expect(parseGraphQLSchema.addGraphQLQuery('get', {})).toBeUndefined();
286280
expect(logged).toBeTruthy();
287281
});
288282

@@ -297,16 +291,16 @@ describe('ParseGraphQLSchema', () => {
297291
},
298292
});
299293
await parseGraphQLSchema.load();
300-
delete parseGraphQLSchema.graphQLObjectsQueries.get;
294+
delete parseGraphQLSchema.graphQLQueries.get;
301295
const field = {};
302-
expect(
303-
parseGraphQLSchema.addGraphQLObjectQuery('get', field, true, true)
304-
).toBe(field);
305-
expect(parseGraphQLSchema.graphQLObjectsQueries['get']).toBe(field);
296+
expect(parseGraphQLSchema.addGraphQLQuery('get', field, true, true)).toBe(
297+
field
298+
);
299+
expect(parseGraphQLSchema.graphQLQueries['get']).toBe(field);
306300
});
307301
});
308302

309-
describe('addGraphQLObjectMutation', () => {
303+
describe('addGraphQLMutation', () => {
310304
it('should not load and warn duplicated mutations', async () => {
311305
let logged = false;
312306
const parseGraphQLSchema = new ParseGraphQLSchema({
@@ -316,21 +310,21 @@ describe('ParseGraphQLSchema', () => {
316310
warn: message => {
317311
logged = true;
318312
expect(message).toEqual(
319-
'Object mutation createSomeClass could not be added to the auto schema because it collided with an existing field.'
313+
'Mutation createSomeClass could not be added to the auto schema because it collided with an existing field.'
320314
);
321315
},
322316
},
323317
});
324318
await parseGraphQLSchema.load();
325319
const field = {};
326320
expect(
327-
parseGraphQLSchema.addGraphQLObjectMutation('createSomeClass', field)
328-
).toBe(field);
329-
expect(
330-
parseGraphQLSchema.graphQLObjectsMutations['createSomeClass']
321+
parseGraphQLSchema.addGraphQLMutation('createSomeClass', field)
331322
).toBe(field);
323+
expect(parseGraphQLSchema.graphQLMutations['createSomeClass']).toBe(
324+
field
325+
);
332326
expect(
333-
parseGraphQLSchema.addGraphQLObjectMutation('createSomeClass', {})
327+
parseGraphQLSchema.addGraphQLMutation('createSomeClass', {})
334328
).toBeUndefined();
335329
expect(logged).toBeTruthy();
336330
});
@@ -348,15 +342,15 @@ describe('ParseGraphQLSchema', () => {
348342
await parseGraphQLSchema.load();
349343
const field = {};
350344
expect(
351-
parseGraphQLSchema.addGraphQLObjectMutation('createSomeClass', field)
352-
).toBe(field);
353-
expect(
354-
parseGraphQLSchema.graphQLObjectsMutations['createSomeClass']
345+
parseGraphQLSchema.addGraphQLMutation('createSomeClass', field)
355346
).toBe(field);
347+
expect(parseGraphQLSchema.graphQLMutations['createSomeClass']).toBe(
348+
field
349+
);
356350
expect(() =>
357-
parseGraphQLSchema.addGraphQLObjectMutation('createSomeClass', {}, true)
351+
parseGraphQLSchema.addGraphQLMutation('createSomeClass', {}, true)
358352
).toThrowError(
359-
'Object mutation createSomeClass could not be added to the auto schema because it collided with an existing field.'
353+
'Mutation createSomeClass could not be added to the auto schema because it collided with an existing field.'
360354
);
361355
});
362356

@@ -369,14 +363,14 @@ describe('ParseGraphQLSchema', () => {
369363
warn: message => {
370364
logged = true;
371365
expect(message).toEqual(
372-
'Object mutation create could not be added to the auto schema because it collided with an existing field.'
366+
'Mutation create could not be added to the auto schema because it collided with an existing field.'
373367
);
374368
},
375369
},
376370
});
377371
await parseGraphQLSchema.load();
378372
expect(
379-
parseGraphQLSchema.addGraphQLObjectMutation('create', {})
373+
parseGraphQLSchema.addGraphQLMutation('create', {})
380374
).toBeUndefined();
381375
expect(logged).toBeTruthy();
382376
});
@@ -392,12 +386,12 @@ describe('ParseGraphQLSchema', () => {
392386
},
393387
});
394388
await parseGraphQLSchema.load();
395-
delete parseGraphQLSchema.graphQLObjectsMutations.create;
389+
delete parseGraphQLSchema.graphQLMutations.create;
396390
const field = {};
397391
expect(
398-
parseGraphQLSchema.addGraphQLObjectMutation('create', field, true, true)
392+
parseGraphQLSchema.addGraphQLMutation('create', field, true, true)
399393
).toBe(field);
400-
expect(parseGraphQLSchema.graphQLObjectsMutations['create']).toBe(field);
394+
expect(parseGraphQLSchema.graphQLMutations['create']).toBe(field);
401395
});
402396
});
403397

@@ -453,27 +447,27 @@ describe('ParseGraphQLSchema', () => {
453447
await parseGraphQLSchema.databaseController.schemaCache.clear();
454448
const schema1 = await parseGraphQLSchema.load();
455449
const types1 = parseGraphQLSchema.graphQLTypes;
456-
const objectQueries1 = parseGraphQLSchema.graphQLObjectsQueries;
457-
const objectMutations1 = parseGraphQLSchema.graphQLObjectsMutations;
450+
const queries1 = parseGraphQLSchema.graphQLQueries;
451+
const mutations1 = parseGraphQLSchema.graphQLMutations;
458452
const user = new Parse.Object('User');
459453
await user.save();
460454
await parseGraphQLSchema.databaseController.schemaCache.clear();
461455
const schema2 = await parseGraphQLSchema.load();
462456
const types2 = parseGraphQLSchema.graphQLTypes;
463-
const objectQueries2 = parseGraphQLSchema.graphQLObjectsQueries;
464-
const objectMutations2 = parseGraphQLSchema.graphQLObjectsMutations;
457+
const queries2 = parseGraphQLSchema.graphQLQueries;
458+
const mutations2 = parseGraphQLSchema.graphQLMutations;
465459
expect(schema1).not.toBe(schema2);
466460
expect(types1).not.toBe(types2);
467461
expect(types1.map(type => type.name).sort()).toEqual(
468462
types2.map(type => type.name).sort()
469463
);
470-
expect(objectQueries1).not.toBe(objectQueries2);
471-
expect(Object.keys(objectQueries1).sort()).toEqual(
472-
Object.keys(objectQueries2).sort()
464+
expect(queries1).not.toBe(queries2);
465+
expect(Object.keys(queries1).sort()).toEqual(
466+
Object.keys(queries2).sort()
473467
);
474-
expect(objectMutations1).not.toBe(objectMutations2);
475-
expect(Object.keys(objectMutations1).sort()).toEqual(
476-
Object.keys(objectMutations2).sort()
468+
expect(mutations1).not.toBe(mutations2);
469+
expect(Object.keys(mutations1).sort()).toEqual(
470+
Object.keys(mutations2).sort()
477471
);
478472
});
479473

@@ -488,27 +482,27 @@ describe('ParseGraphQLSchema', () => {
488482
await parseGraphQLSchema.databaseController.schemaCache.clear();
489483
const schema1 = await parseGraphQLSchema.load();
490484
const types1 = parseGraphQLSchema.graphQLTypes;
491-
const objectQueries1 = parseGraphQLSchema.graphQLObjectsQueries;
492-
const objectMutations1 = parseGraphQLSchema.graphQLObjectsMutations;
485+
const queries1 = parseGraphQLSchema.graphQLQueries;
486+
const mutations1 = parseGraphQLSchema.graphQLMutations;
493487
const car2 = new Parse.Object('car');
494488
await car2.save();
495489
await parseGraphQLSchema.databaseController.schemaCache.clear();
496490
const schema2 = await parseGraphQLSchema.load();
497491
const types2 = parseGraphQLSchema.graphQLTypes;
498-
const objectQueries2 = parseGraphQLSchema.graphQLObjectsQueries;
499-
const objectMutations2 = parseGraphQLSchema.graphQLObjectsMutations;
492+
const queries2 = parseGraphQLSchema.graphQLQueries;
493+
const mutations2 = parseGraphQLSchema.graphQLMutations;
500494
expect(schema1).not.toBe(schema2);
501495
expect(types1).not.toBe(types2);
502496
expect(types1.map(type => type.name).sort()).toEqual(
503497
types2.map(type => type.name).sort()
504498
);
505-
expect(objectQueries1).not.toBe(objectQueries2);
506-
expect(Object.keys(objectQueries1).sort()).toEqual(
507-
Object.keys(objectQueries2).sort()
499+
expect(queries1).not.toBe(queries2);
500+
expect(Object.keys(queries1).sort()).toEqual(
501+
Object.keys(queries2).sort()
508502
);
509-
expect(objectMutations1).not.toBe(objectMutations2);
510-
expect(Object.keys(objectMutations1).sort()).toEqual(
511-
Object.keys(objectMutations2).sort()
503+
expect(mutations1).not.toBe(mutations2);
504+
expect(Object.keys(mutations1).sort()).toEqual(
505+
Object.keys(mutations2).sort()
512506
);
513507
});
514508

@@ -522,25 +516,25 @@ describe('ParseGraphQLSchema', () => {
522516
await car.save();
523517
await parseGraphQLSchema.databaseController.schemaCache.clear();
524518
const schema1 = await parseGraphQLSchema.load();
525-
const objectQueries1 = parseGraphQLSchema.graphQLObjectsQueries;
526-
const objectMutations1 = parseGraphQLSchema.graphQLObjectsMutations;
519+
const queries1 = parseGraphQLSchema.graphQLQueries;
520+
const mutations1 = parseGraphQLSchema.graphQLMutations;
527521
const cars = new Parse.Object('cars');
528522
await cars.save();
529523
await parseGraphQLSchema.databaseController.schemaCache.clear();
530524
const schema2 = await parseGraphQLSchema.load();
531-
const objectQueries2 = parseGraphQLSchema.graphQLObjectsQueries;
532-
const objectMutations2 = parseGraphQLSchema.graphQLObjectsMutations;
525+
const queries2 = parseGraphQLSchema.graphQLQueries;
526+
const mutations2 = parseGraphQLSchema.graphQLMutations;
533527
expect(schema1).not.toBe(schema2);
534-
expect(objectQueries1).not.toBe(objectQueries2);
535-
expect(Object.keys(objectQueries1).sort()).toEqual(
536-
Object.keys(objectQueries2).sort()
528+
expect(queries1).not.toBe(queries2);
529+
expect(Object.keys(queries1).sort()).toEqual(
530+
Object.keys(queries2).sort()
537531
);
538-
expect(objectMutations1).not.toBe(objectMutations2);
532+
expect(mutations1).not.toBe(mutations2);
539533
expect(
540-
Object.keys(objectMutations1)
534+
Object.keys(mutations1)
541535
.concat('createCars', 'updateCars', 'deleteCars')
542536
.sort()
543-
).toEqual(Object.keys(objectMutations2).sort());
537+
).toEqual(Object.keys(mutations2).sort());
544538
});
545539
});
546540
});

0 commit comments

Comments
 (0)