@@ -2,6 +2,8 @@ import { buildSchema } from 'graphql';
22import { GraphQLSchema } from 'graphql/type/schema' ;
33import buildTypeWeightsFromSchema from '../../src/analysis/buildTypeWeights' ;
44
5+
6+ // these types allow the tests to overwite properties on the typeWeightObject
57interface TestFields {
68 [ index : string ] : number ;
79}
@@ -196,8 +198,7 @@ xdescribe('Test buildTypeWeightsFromSchema function', () => {
196198 } ) ;
197199 } ) ;
198200
199- // ? varibale weight
200- test ( 'fields returning lists of objects' , ( ) => {
201+ test ( 'fields returning lists of objects of determinate size' , ( ) => {
201202 schema = buildSchema ( `
202203 type Query {
203204 reviews(episode: Episode!, first: Int): [Review]
@@ -215,13 +216,17 @@ xdescribe('Test buildTypeWeightsFromSchema function', () => {
215216 expect ( buildTypeWeightsFromSchema ( schema ) ) . toEqual ( {
216217 Query : {
217218 weight : 1 ,
218- fields : { } ,
219+ fields : {
220+ // FIXME: check the best solution during implementation and update the tests here.
221+ reviews : ( arg : number , type : Type ) => arg * type . weight ,
222+ // code from PR review -> reviews: (type) => args[multiplierName] * typeWeightObject[type].weight
223+ } ,
219224 } ,
220225 Review : {
221- weight : 1 , // ? weight is the argument passed as 'first'. it's variable...
226+ weight : 1 ,
222227 fields : {
223- id : 0 ,
224- name : 0 ,
228+ stars : 0 ,
229+ commentary : 0 ,
225230 } ,
226231 } ,
227232 Episode : {
@@ -231,44 +236,63 @@ xdescribe('Test buildTypeWeightsFromSchema function', () => {
231236 } ) ;
232237 } ) ;
233238
239+ // TODO: need to figure out how to handle this situation. Skip for now.
240+ // The field friends returns a list of an unknown number of objects.
241+ xtest ( 'fields returning lists of objects of indetermitae size' , ( ) => {
242+ schema = buildSchema ( `
243+ type Human {
244+ id: ID!
245+ name: String!
246+ homePlanet: String
247+ friends: [Human]
248+ }
249+ ` ) ;
250+ expect ( buildTypeWeightsFromSchema ( schema ) ) . toEqual ( {
251+ Human : {
252+ weight : 1 ,
253+ fields : {
254+ // FIXME: check the best solution during implementation and update the tests here.
255+ friends : ( arg : number , type : Type ) => arg * type . weight ,
256+ } ,
257+ } ,
258+ } ) ;
259+ } ) ;
260+
234261 test ( 'interface types' , ( ) => {
235262 schema = buildSchema ( `
236263 interface Character {
237264 id: ID!
238- name: String!
239- friends: [Character]
265+ name: String!
240266 }
241267
242268 type Human implements Character {
243269 id: ID!
244270 name: String!
245271 homePlanet: String
246- friends: [Character]
247272 }
248273
249274 type Droid implements Character {
250275 id: ID!
251- name: String!
252- friends: [Character]
276+ name: String!
253277 primaryFunction: String
254278 }` ) ;
255279 expect ( buildTypeWeightsFromSchema ( schema ) ) . toEqual ( {
256- character : {
280+ Character : {
257281 weight : 1 ,
258282 fields : {
259283 id : 0 ,
260284 name : 0 ,
261285 } ,
262286 } ,
263- human : {
287+ Human : {
264288 weight : 1 ,
265289 fields : {
266290 id : 0 ,
267291 name : 0 ,
268292 homePlanet : 0 ,
269293 } ,
270294 } ,
271- droid : {
295+ Droid : {
272296 weight : 1 ,
273297 fields : {
274298 id : 0 ,
0 commit comments