Skip to content

Commit

Permalink
fix: remove edges field from projection argument provided to `findM…
Browse files Browse the repository at this point in the history
…any` resolver

relates #75
  • Loading branch information
nodkz committed May 25, 2021
1 parent d56bdaa commit 8d7e108
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
'@typescript-eslint/no-empty-function': 0,
'@typescript-eslint/camelcase': 0,
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }],
},
env: {
jasmine: true,
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
testEnvironment: 'node',
globals: {
'ts-jest': {
tsConfig: '<rootDir>/tsconfig.json',
tsconfig: '<rootDir>/tsconfig.json',
isolatedModules: true,
diagnostics: false,
},
Expand Down
21 changes: 17 additions & 4 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ResolverResolveParams,
ObjectTypeComposerArgumentConfigMap,
ObjectTypeComposerFieldConfigMap,
ProjectionType,
} from 'graphql-compose';
import { prepareConnectionType, PageInfoType, ConnectionType } from './types/connectionType';
import { prepareSortType } from './types/sortInputType';
Expand Down Expand Up @@ -156,12 +157,24 @@ export function prepareConnectionResolver<TSource, TContext>(
countPromise = Promise.resolve(0);
}

if (projection && projection.edges) {
if (projection?.edges) {
// combine top level projection
// (maybe somebody add additional fields via resolveParams.projection)
// (maybe somebody provided additional fields via resolveParams.projection)
// and edges.node (record needed fields)
const extraProjection = opts.edgeFields ? projection.edges : projection.edges.node;
findManyParams.projection = { ...projection, ...extraProjection };
const { edges, ...projectionWithoutEdges } = projection;
const extraProjection = {} as ProjectionType;
if (opts.edgeFields) {
Object.keys(opts.edgeFields).forEach((extraKey) => {
if (projection.edges[extraKey]) {
extraProjection[extraKey] = projection.edges[extraKey];
}
});
}
findManyParams.projection = {
...projectionWithoutEdges,
...projection?.edges?.node,
...extraProjection,
};
} else {
findManyParams.projection = { ...projection };
}
Expand Down

0 comments on commit 8d7e108

Please sign in to comment.