Skip to content

Commit 31f298a

Browse files
authored
Merge pull request #5861 from darrellwarde/fix/5595-overfetching
Filter fields with `@customResolver` from projection
2 parents 56de1c7 + f2e1575 commit 31f298a

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

.changeset/breezy-jars-design.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@neo4j/graphql": patch
3+
---
4+
5+
Fixed bug where fields decorated with `@customResolver` were included in the projection of the generated Cypher query

packages/graphql/src/translate/queryAST/factory/FieldFactory.ts

+10
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ export class FieldFactory {
7777
context,
7878
field: field.name,
7979
});
80+
81+
const attribute = entity.findAttribute(fieldName);
82+
if (attribute) {
83+
const customResolver = attribute.annotations.customResolver;
84+
if (customResolver) {
85+
// We don't want to project the custom resolver field itself
86+
return;
87+
}
88+
}
89+
8090
const relationship = entity.findRelationship(fieldName);
8191
if (relationship) {
8292
if (isConnection) {

packages/graphql/tests/tck/directives/customResolver.test.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe("@customResolver directive", () => {
8080

8181
expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
8282
"MATCH (this:User)
83-
RETURN this { .firstName, .lastName, .fullName } AS this"
83+
RETURN this { .firstName, .lastName } AS this"
8484
`);
8585

8686
expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
@@ -100,7 +100,7 @@ describe("@customResolver directive", () => {
100100

101101
expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
102102
"MATCH (this:User)
103-
RETURN this { .firstName, .fullName, .lastName } AS this"
103+
RETURN this { .firstName, .lastName } AS this"
104104
`);
105105

106106
expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
@@ -119,7 +119,7 @@ describe("@customResolver directive", () => {
119119

120120
expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
121121
"MATCH (this:User)
122-
RETURN this { .fullName, .firstName, .lastName } AS this"
122+
RETURN this { .firstName, .lastName } AS this"
123123
`);
124124

125125
expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
@@ -162,7 +162,7 @@ describe("@customResolver directive", () => {
162162

163163
expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
164164
"MATCH (this:User)
165-
RETURN this { .firstName, .fullName } AS this"
165+
RETURN this { .firstName } AS this"
166166
`);
167167

168168
expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
@@ -181,7 +181,7 @@ describe("@customResolver directive", () => {
181181

182182
expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
183183
"MATCH (this:User)
184-
RETURN this { .fullName } AS this"
184+
RETURN this { } AS this"
185185
`);
186186

187187
expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
@@ -256,7 +256,7 @@ describe("@customResolver directive", () => {
256256
WITH this1 { city: var4 } AS this1
257257
RETURN head(collect(this1)) AS var5
258258
}
259-
RETURN this { .firstName, .lastName, .fullName, address: var5 } AS this"
259+
RETURN this { .firstName, .lastName, address: var5 } AS this"
260260
`);
261261

262262
expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
@@ -312,7 +312,7 @@ describe("@customResolver directive", () => {
312312
WITH this1 { city: var4 } AS this1
313313
RETURN head(collect(this1)) AS var5
314314
}
315-
RETURN this { .lastName, .fullName, .firstName, address: var5 } AS this"
315+
RETURN this { .lastName, .firstName, address: var5 } AS this"
316316
`);
317317

318318
expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
@@ -343,7 +343,7 @@ describe("@customResolver directive", () => {
343343
WITH this1 { city: var4 } AS this1
344344
RETURN head(collect(this1)) AS var5
345345
}
346-
RETURN this { .fullName, .firstName, .lastName, address: var5 } AS this"
346+
RETURN this { .firstName, .lastName, address: var5 } AS this"
347347
`);
348348

349349
expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
@@ -425,7 +425,7 @@ describe("@customResolver directive", () => {
425425
WITH var2
426426
RETURN collect(var2) AS var2
427427
}
428-
RETURN this { .name, .publicationsWithAuthor, publications: var2 } AS this"
428+
RETURN this { .name, publications: var2 } AS this"
429429
`);
430430

431431
expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
@@ -484,7 +484,7 @@ describe("@customResolver directive", () => {
484484
WITH var2
485485
RETURN collect(var2) AS var2
486486
}
487-
RETURN this { .publicationsWithAuthor, .name, publications: var2 } AS this"
487+
RETURN this { .name, publications: var2 } AS this"
488488
`);
489489

490490
expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
@@ -519,7 +519,7 @@ describe("@customResolver directive", () => {
519519
WITH var2
520520
RETURN collect(var2) AS var2
521521
}
522-
RETURN this { .publicationsWithAuthor, .name, publications: var2 } AS this"
522+
RETURN this { .name, publications: var2 } AS this"
523523
`);
524524

525525
expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
@@ -606,7 +606,7 @@ describe("@customResolver directive", () => {
606606
WITH var2
607607
RETURN collect(var2) AS var2
608608
}
609-
RETURN this { .name, .publicationsWithAuthor, publications: var2 } AS this"
609+
RETURN this { .name, publications: var2 } AS this"
610610
`);
611611

612612
expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
@@ -665,7 +665,7 @@ describe("@customResolver directive", () => {
665665
WITH var2
666666
RETURN collect(var2) AS var2
667667
}
668-
RETURN this { .publicationsWithAuthor, .name, publications: var2 } AS this"
668+
RETURN this { .name, publications: var2 } AS this"
669669
`);
670670

671671
expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
@@ -700,7 +700,7 @@ describe("@customResolver directive", () => {
700700
WITH var2
701701
RETURN collect(var2) AS var2
702702
}
703-
RETURN this { .publicationsWithAuthor, .name, publications: var2 } AS this"
703+
RETURN this { .name, publications: var2 } AS this"
704704
`);
705705

706706
expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);

0 commit comments

Comments
 (0)