Skip to content

Commit

Permalink
Merge pull request #5861 from darrellwarde/fix/5595-overfetching
Browse files Browse the repository at this point in the history
Filter fields with `@customResolver` from projection
  • Loading branch information
darrellwarde authored Dec 3, 2024
2 parents 56de1c7 + f2e1575 commit 31f298a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-jars-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/graphql": patch
---

Fixed bug where fields decorated with `@customResolver` were included in the projection of the generated Cypher query
10 changes: 10 additions & 0 deletions packages/graphql/src/translate/queryAST/factory/FieldFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ export class FieldFactory {
context,
field: field.name,
});

const attribute = entity.findAttribute(fieldName);
if (attribute) {
const customResolver = attribute.annotations.customResolver;
if (customResolver) {
// We don't want to project the custom resolver field itself
return;
}
}

const relationship = entity.findRelationship(fieldName);
if (relationship) {
if (isConnection) {
Expand Down
28 changes: 14 additions & 14 deletions packages/graphql/tests/tck/directives/customResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe("@customResolver directive", () => {

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:User)
RETURN this { .firstName, .lastName, .fullName } AS this"
RETURN this { .firstName, .lastName } AS this"
`);

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

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:User)
RETURN this { .firstName, .fullName, .lastName } AS this"
RETURN this { .firstName, .lastName } AS this"
`);

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

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:User)
RETURN this { .fullName, .firstName, .lastName } AS this"
RETURN this { .firstName, .lastName } AS this"
`);

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

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:User)
RETURN this { .firstName, .fullName } AS this"
RETURN this { .firstName } AS this"
`);

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

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:User)
RETURN this { .fullName } AS this"
RETURN this { } AS this"
`);

expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
Expand Down Expand Up @@ -256,7 +256,7 @@ describe("@customResolver directive", () => {
WITH this1 { city: var4 } AS this1
RETURN head(collect(this1)) AS var5
}
RETURN this { .firstName, .lastName, .fullName, address: var5 } AS this"
RETURN this { .firstName, .lastName, address: var5 } AS this"
`);

expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
Expand Down Expand Up @@ -312,7 +312,7 @@ describe("@customResolver directive", () => {
WITH this1 { city: var4 } AS this1
RETURN head(collect(this1)) AS var5
}
RETURN this { .lastName, .fullName, .firstName, address: var5 } AS this"
RETURN this { .lastName, .firstName, address: var5 } AS this"
`);

expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
Expand Down Expand Up @@ -343,7 +343,7 @@ describe("@customResolver directive", () => {
WITH this1 { city: var4 } AS this1
RETURN head(collect(this1)) AS var5
}
RETURN this { .fullName, .firstName, .lastName, address: var5 } AS this"
RETURN this { .firstName, .lastName, address: var5 } AS this"
`);

expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
Expand Down Expand Up @@ -425,7 +425,7 @@ describe("@customResolver directive", () => {
WITH var2
RETURN collect(var2) AS var2
}
RETURN this { .name, .publicationsWithAuthor, publications: var2 } AS this"
RETURN this { .name, publications: var2 } AS this"
`);

expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
Expand Down Expand Up @@ -484,7 +484,7 @@ describe("@customResolver directive", () => {
WITH var2
RETURN collect(var2) AS var2
}
RETURN this { .publicationsWithAuthor, .name, publications: var2 } AS this"
RETURN this { .name, publications: var2 } AS this"
`);

expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
Expand Down Expand Up @@ -519,7 +519,7 @@ describe("@customResolver directive", () => {
WITH var2
RETURN collect(var2) AS var2
}
RETURN this { .publicationsWithAuthor, .name, publications: var2 } AS this"
RETURN this { .name, publications: var2 } AS this"
`);

expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
Expand Down Expand Up @@ -606,7 +606,7 @@ describe("@customResolver directive", () => {
WITH var2
RETURN collect(var2) AS var2
}
RETURN this { .name, .publicationsWithAuthor, publications: var2 } AS this"
RETURN this { .name, publications: var2 } AS this"
`);

expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
Expand Down Expand Up @@ -665,7 +665,7 @@ describe("@customResolver directive", () => {
WITH var2
RETURN collect(var2) AS var2
}
RETURN this { .publicationsWithAuthor, .name, publications: var2 } AS this"
RETURN this { .name, publications: var2 } AS this"
`);

expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`);
Expand Down Expand Up @@ -700,7 +700,7 @@ describe("@customResolver directive", () => {
WITH var2
RETURN collect(var2) AS var2
}
RETURN this { .publicationsWithAuthor, .name, publications: var2 } AS this"
RETURN this { .name, publications: var2 } AS this"
`);

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

0 comments on commit 31f298a

Please sign in to comment.