Skip to content

Commit 8d7e108

Browse files
committed
fix: remove edges field from projection argument provided to findMany resolver
relates #75
1 parent d56bdaa commit 8d7e108

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = {
3838
'@typescript-eslint/no-empty-function': 0,
3939
'@typescript-eslint/camelcase': 0,
4040
'@typescript-eslint/ban-ts-comment': 0,
41+
'@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }],
4142
},
4243
env: {
4344
jasmine: true,

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
testEnvironment: 'node',
44
globals: {
55
'ts-jest': {
6-
tsConfig: '<rootDir>/tsconfig.json',
6+
tsconfig: '<rootDir>/tsconfig.json',
77
isolatedModules: true,
88
diagnostics: false,
99
},

src/connection.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
ResolverResolveParams,
66
ObjectTypeComposerArgumentConfigMap,
77
ObjectTypeComposerFieldConfigMap,
8+
ProjectionType,
89
} from 'graphql-compose';
910
import { prepareConnectionType, PageInfoType, ConnectionType } from './types/connectionType';
1011
import { prepareSortType } from './types/sortInputType';
@@ -156,12 +157,24 @@ export function prepareConnectionResolver<TSource, TContext>(
156157
countPromise = Promise.resolve(0);
157158
}
158159

159-
if (projection && projection.edges) {
160+
if (projection?.edges) {
160161
// combine top level projection
161-
// (maybe somebody add additional fields via resolveParams.projection)
162+
// (maybe somebody provided additional fields via resolveParams.projection)
162163
// and edges.node (record needed fields)
163-
const extraProjection = opts.edgeFields ? projection.edges : projection.edges.node;
164-
findManyParams.projection = { ...projection, ...extraProjection };
164+
const { edges, ...projectionWithoutEdges } = projection;
165+
const extraProjection = {} as ProjectionType;
166+
if (opts.edgeFields) {
167+
Object.keys(opts.edgeFields).forEach((extraKey) => {
168+
if (projection.edges[extraKey]) {
169+
extraProjection[extraKey] = projection.edges[extraKey];
170+
}
171+
});
172+
}
173+
findManyParams.projection = {
174+
...projectionWithoutEdges,
175+
...projection?.edges?.node,
176+
...extraProjection,
177+
};
165178
} else {
166179
findManyParams.projection = { ...projection };
167180
}

0 commit comments

Comments
 (0)