Skip to content

Commit f2240d7

Browse files
committed
fix projection for node
1 parent 4030e04 commit f2240d7

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

src/__tests__/composeWithConnection-test.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
graphql,
1010
GraphQLSchema,
1111
} from 'graphql';
12+
import projection from 'graphql-compose/lib/projection';
13+
1214

1315
describe('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
});

src/resolvers/connectionResolver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export function prepareConnectionResolver(
9595
findManyParams.args.filter = prepareFilter(args);
9696
findManyParams.args.sort = sortOptions.sortValue;
9797

98-
findManyParams.projection = projection;
98+
findManyParams.projection = projection && projection.edges && projection.edges.node;
9999
sortOptions.uniqueFields.forEach(fieldName => {
100100
findManyParams.projection[fieldName] = true;
101101
});

0 commit comments

Comments
 (0)