99 graphql ,
1010 GraphQLSchema ,
1111} from 'graphql' ;
12+ import projection from 'graphql-compose/lib/projection' ;
13+
1214
1315describe ( 'composeWithRelay' , ( ) => {
1416 const userComposer = composeWithConnection ( userTypeComposer , {
@@ -146,7 +148,7 @@ describe('composeWithRelay', () => {
146148 expect ( result )
147149 . deep . property ( 'data.userConnection' )
148150 . deep . equals ( {
149- count : 0 , // TODO fix projection in graphql-compose, should be 15
151+ count : 15 ,
150152 pageInfo :
151153 { startCursor : 'eyJhZ2UiOjQ5LCJpZCI6MTF9' ,
152154 endCursor : 'eyJhZ2UiOjQ3LCJpZCI6MTJ9' ,
@@ -168,4 +170,53 @@ describe('composeWithRelay', () => {
168170 ] ,
169171 } ) ;
170172 } ) ;
173+
174+ describe ( 'projection()' , ( ) => {
175+ it . only ( 'should return object' , async ( ) => {
176+ // const resolver = userTypeComposer.getResolver('connection');
177+ // const resolve = resolver.resolve;
178+ // resolver.resolve = (resolveParams) => {
179+ // const pr = projection(resolveParams.info);
180+ // console.log(pr);
181+ // resolve(resolveParams);
182+ // };
183+
184+ rootQueryTypeComposer . addField ( 'userConnection' ,
185+ userTypeComposer . getResolver ( 'connection' ) . getFieldConfig ( )
186+ ) ;
187+ const schema = new GraphQLSchema ( {
188+ query : rootQueryTypeComposer . getType ( ) ,
189+ } ) ;
190+ const query = `{
191+ userConnection(first: 3) {
192+ count,
193+ pageInfo {
194+ startCursor
195+ endCursor
196+ ...on PageInfo {
197+ hasPreviousPage
198+ hasNextPage
199+ }
200+ }
201+ edges {
202+ cursor
203+ node {
204+ id
205+ name
206+ ...idNameAge
207+ ...on User {
208+ age
209+ }
210+ }
211+ }
212+ }
213+ }
214+ fragment idNameAge on User {
215+ gender
216+ }
217+ ` ;
218+ const result = await graphql ( schema , query ) ;
219+ // console.log(result.data.userConnection.edges);
220+ } )
221+ } ) ;
171222} ) ;
0 commit comments