Skip to content

fix: remove edges field from projection argument provided to findMany resolver #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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