@@ -46,6 +46,25 @@ describe('Test buildTypeWeightsFromSchema function', () => {
4646 } ) ;
4747 } ) ;
4848
49+ test ( 'a single mutation type' , ( ) => {
50+ schema = buildSchema ( `
51+ type Mutation {
52+ name: String
53+ email: String
54+ }
55+ ` ) ;
56+
57+ expect ( buildTypeWeightsFromSchema ( schema ) ) . toEqual ( {
58+ mutation : {
59+ weight : 10 ,
60+ fields : {
61+ name : { weight : 0 } ,
62+ email : { weight : 0 } ,
63+ } ,
64+ } ,
65+ } ) ;
66+ } ) ;
67+
4968 test ( 'multiple types' , ( ) => {
5069 schema = buildSchema ( `
5170 type Query {
@@ -214,6 +233,185 @@ describe('Test buildTypeWeightsFromSchema function', () => {
214233 } ) ;
215234 } ) ;
216235
236+ test ( 'interface types' , ( ) => {
237+ schema = buildSchema ( `
238+ interface Character {
239+ id: ID!
240+ name: String!
241+ }
242+
243+ type Human implements Character {
244+ id: ID!
245+ name: String!
246+ homePlanet: String
247+ }
248+
249+ type Droid implements Character {
250+ id: ID!
251+ name: String!
252+ primaryFunction: String
253+ }` ) ;
254+ expect ( buildTypeWeightsFromSchema ( schema ) ) . toEqual ( {
255+ character : {
256+ weight : 1 ,
257+ fields : {
258+ id : { weight : 0 } ,
259+ name : { weight : 0 } ,
260+ } ,
261+ } ,
262+ human : {
263+ weight : 1 ,
264+ fields : {
265+ id : { weight : 0 } ,
266+ name : { weight : 0 } ,
267+ homePlanet : { weight : 0 } ,
268+ } ,
269+ } ,
270+ droid : {
271+ weight : 1 ,
272+ fields : {
273+ id : { weight : 0 } ,
274+ name : { weight : 0 } ,
275+ primaryFunction : { weight : 0 } ,
276+ } ,
277+ } ,
278+ } ) ;
279+ } ) ;
280+
281+ // FIXME: need to figure out how to handle this situation. Skip for now.
282+ // The field 'friends' returns a list of an unknown number of objects.
283+ xtest ( 'fields returning lists of objects of indeterminate size' , ( ) => {
284+ schema = buildSchema ( `
285+ type Human {
286+ id: ID!
287+ name: String!
288+ homePlanet: String
289+ friends: [Human]
290+ }
291+ ` ) ;
292+ expect ( buildTypeWeightsFromSchema ( schema ) ) . toEqual ( {
293+ human : {
294+ weight : 1 ,
295+ fields : {
296+ id : { weight : 0 } ,
297+ name : { weight : 0 } ,
298+ hamePlanet : { weight : 0 } ,
299+ friends : {
300+ resolvesTo : 'human' ,
301+ weight : expect . any ( Function ) ,
302+ } ,
303+ } ,
304+ } ,
305+ } ) ;
306+ } ) ;
307+
308+ describe ( 'mutation types...' , ( ) => {
309+ test ( 'a mutation type and a query type' , ( ) => {
310+ schema = buildSchema ( `
311+ type Query {
312+ name: String
313+ email: String
314+ }
315+
316+ type Mutation {
317+ name: String
318+ email: String
319+ }
320+ ` ) ;
321+
322+ expect ( buildTypeWeightsFromSchema ( schema ) ) . toEqual ( {
323+ mutation : {
324+ weight : 10 ,
325+ fields : {
326+ name : { weight : 0 } ,
327+ email : { weight : 0 } ,
328+ } ,
329+ } ,
330+ query : {
331+ weight : 1 ,
332+ fields : {
333+ name : { weight : 0 } ,
334+ email : { weight : 0 } ,
335+ } ,
336+ } ,
337+ } ) ;
338+ } ) ;
339+
340+ test ( 'a mutation type and a query type' , ( ) => {
341+ schema = buildSchema ( `
342+ type Mutation {
343+ login(user: UserInput!): User
344+ }
345+ type User{
346+ id: ID!
347+ email: String!
348+ password: String!
349+ }
350+ input UserInput {
351+ email: String!
352+ password: String!
353+ }
354+ ` ) ;
355+
356+ expect ( buildTypeWeightsFromSchema ( schema ) ) . toEqual ( {
357+ mutation : {
358+ weight : 10 ,
359+ fields : {
360+ name : { weight : 0 } ,
361+ email : { weight : 0 } ,
362+ } ,
363+ } ,
364+ user : {
365+ weight : 1 ,
366+ fields : {
367+ id : { weight : 0 } ,
368+ email : { weight : 0 } ,
369+ password : { weight : 0 } ,
370+ } ,
371+ } ,
372+ } ) ;
373+ } ) ;
374+
375+ // ?mutation and an output type
376+ xtest ( 'a mutation type and a query type' , ( ) => {
377+ schema = buildSchema ( `
378+ type Mutation {
379+ login(user: UserInput!): User
380+ }
381+ type User{
382+ id: ID!
383+ email: String!
384+ password: String!
385+ }
386+ input UserInput {
387+ email: String!
388+ password: String!
389+ }
390+ ` ) ;
391+
392+ expect ( buildTypeWeightsFromSchema ( schema ) ) . toEqual ( {
393+ mutation : {
394+ weight : 10 ,
395+ fields : {
396+ name : { weight : 0 } ,
397+ email : { weight : 0 } ,
398+ } ,
399+ } ,
400+ user : {
401+ weight : 1 ,
402+ fields : {
403+ id : { weight : 0 } ,
404+ email : { weight : 0 } ,
405+ password : { weight : 0 } ,
406+ } ,
407+ } ,
408+ } ) ;
409+ } ) ;
410+ // mutations with lists
411+
412+ // mutations with nonNull
413+ } ) ;
414+
217415 describe ( 'fields returning lists of objects of determinate size and...' , ( ) => {
218416 test ( 'args include limiting keywords: "first", "last", "limit"' , ( ) => {
219417 schema = buildSchema ( `
@@ -388,78 +586,6 @@ describe('Test buildTypeWeightsFromSchema function', () => {
388586 } ) ;
389587 } ) ;
390588
391- // FIXME: need to figure out how to handle this situation. Skip for now.
392- // The field 'friends' returns a list of an unknown number of objects.
393- xtest ( 'fields returning lists of objects of indeterminate size' , ( ) => {
394- schema = buildSchema ( `
395- type Human {
396- id: ID!
397- name: String!
398- homePlanet: String
399- friends: [Human]
400- }
401- ` ) ;
402- expect ( buildTypeWeightsFromSchema ( schema ) ) . toEqual ( {
403- human : {
404- weight : 1 ,
405- fields : {
406- id : { weight : 0 } ,
407- name : { weight : 0 } ,
408- hamePlanet : { weight : 0 } ,
409- friends : {
410- resolvesTo : 'human' ,
411- weight : expect . any ( Function ) ,
412- } ,
413- } ,
414- } ,
415- } ) ;
416- } ) ;
417-
418- test ( 'interface types' , ( ) => {
419- schema = buildSchema ( `
420- interface Character {
421- id: ID!
422- name: String!
423- }
424-
425- type Human implements Character {
426- id: ID!
427- name: String!
428- homePlanet: String
429- }
430-
431- type Droid implements Character {
432- id: ID!
433- name: String!
434- primaryFunction: String
435- }` ) ;
436- expect ( buildTypeWeightsFromSchema ( schema ) ) . toEqual ( {
437- character : {
438- weight : 1 ,
439- fields : {
440- id : { weight : 0 } ,
441- name : { weight : 0 } ,
442- } ,
443- } ,
444- human : {
445- weight : 1 ,
446- fields : {
447- id : { weight : 0 } ,
448- name : { weight : 0 } ,
449- homePlanet : { weight : 0 } ,
450- } ,
451- } ,
452- droid : {
453- weight : 1 ,
454- fields : {
455- id : { weight : 0 } ,
456- name : { weight : 0 } ,
457- primaryFunction : { weight : 0 } ,
458- } ,
459- } ,
460- } ) ;
461- } ) ;
462-
463589 describe ( 'union types with ...' , ( ) => {
464590 test ( 'lists of union types and scalars' , ( ) => {
465591 schema = buildSchema ( `
0 commit comments