9
9
graphql ,
10
10
GraphQLSchema ,
11
11
} from 'graphql' ;
12
+ import projection from 'graphql-compose/lib/projection' ;
13
+
12
14
13
15
describe ( 'composeWithRelay' , ( ) => {
14
16
const userComposer = composeWithConnection ( userTypeComposer , {
@@ -146,7 +148,7 @@ describe('composeWithRelay', () => {
146
148
expect ( result )
147
149
. deep . property ( 'data.userConnection' )
148
150
. deep . equals ( {
149
- count : 0 , // TODO fix projection in graphql-compose, should be 15
151
+ count : 15 ,
150
152
pageInfo :
151
153
{ startCursor : 'eyJhZ2UiOjQ5LCJpZCI6MTF9' ,
152
154
endCursor : 'eyJhZ2UiOjQ3LCJpZCI6MTJ9' ,
@@ -168,4 +170,53 @@ describe('composeWithRelay', () => {
168
170
] ,
169
171
} ) ;
170
172
} ) ;
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
+ } ) ;
171
222
} ) ;
0 commit comments