From 6093e52c573ad37453109a3929f6cb11331fd314 Mon Sep 17 00:00:00 2001 From: Daniel Starns Date: Fri, 30 Jul 2021 15:05:19 +0100 Subject: [PATCH 1/4] docs: add 2.0.0 banner on home page (#371) --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 842683f5db..4860243832 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ 💡 Welcome to the Monorepo for [Neo4j](https://neo4j.com/) + [GraphQL](https://graphql.org/). +> We are working on Neo4j GraphQL 2.0.0, you can download the release candidate via `npm install @neo4j/graphql@next` and checkout the docs [here](https://neo4j.com/docs/graphql-manual/2.0/). + ![Neo4j + GraphQL](./docs/images/banner.png)

From 8479e80c1de297c797221b2ebfb5f3ce65f3380a Mon Sep 17 00:00:00 2001 From: dmoree Date: Thu, 5 Aug 2021 14:58:17 -0700 Subject: [PATCH 2/4] refactor: use alias for params and name for fields --- .../create-connection-and-params.ts | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/graphql/src/translate/connection/create-connection-and-params.ts b/packages/graphql/src/translate/connection/create-connection-and-params.ts index 76814966fe..6b395632bb 100644 --- a/packages/graphql/src/translate/connection/create-connection-and-params.ts +++ b/packages/graphql/src/translate/connection/create-connection-and-params.ts @@ -132,7 +132,7 @@ function createConnectionAndParams({ context, nodeVariable: relatedNodeVariable, parameterPrefix: `${parameterPrefix ? `${parameterPrefix}.` : `${nodeVariable}_`}${ - resolveTree.name + resolveTree.alias }.edges.node`, }); nestedSubqueries.push(nestedConnection[0]); @@ -141,7 +141,7 @@ function createConnectionAndParams({ ...globalParams, ...Object.entries(nestedConnection[1]).reduce>( (res, [k, v]) => { - if (k !== `${relatedNodeVariable}_${connectionResolveTree.name}`) { + if (k !== `${relatedNodeVariable}_${connectionResolveTree.alias}`) { res[k] = v; } return res; @@ -150,13 +150,15 @@ function createConnectionAndParams({ ), }; - if (nestedConnection[1][`${relatedNodeVariable}_${connectionResolveTree.name}`]) { + if (nestedConnection[1][`${relatedNodeVariable}_${connectionResolveTree.alias}`]) { if (!nestedConnectionFieldParams) nestedConnectionFieldParams = {}; nestedConnectionFieldParams = { ...nestedConnectionFieldParams, ...{ - [connectionResolveTree.name]: - nestedConnection[1][`${relatedNodeVariable}_${connectionResolveTree.name}`], + [connectionResolveTree.alias]: + nestedConnection[1][ + `${relatedNodeVariable}_${connectionResolveTree.alias}` + ], }, }; } @@ -197,7 +199,7 @@ function createConnectionAndParams({ relationshipVariable, context, parameterPrefix: `${parameterPrefix ? `${parameterPrefix}.` : `${nodeVariable}_`}${ - resolveTree.name + resolveTree.alias }.args.where.${n.name}`, }); const [whereClause] = where; @@ -268,7 +270,7 @@ function createConnectionAndParams({ relationshipVariable, context, parameterPrefix: `${parameterPrefix ? `${parameterPrefix}.` : `${nodeVariable}_`}${ - resolveTree.name + resolveTree.alias }.args.where`, }); const [whereClause] = where; @@ -350,7 +352,7 @@ function createConnectionAndParams({ context, nodeVariable: relatedNodeVariable, parameterPrefix: `${parameterPrefix ? `${parameterPrefix}.` : `${nodeVariable}_`}${ - resolveTree.name + resolveTree.alias }.edges.node`, }); nestedSubqueries.push(nestedConnection[0]); @@ -358,20 +360,20 @@ function createConnectionAndParams({ globalParams = { ...globalParams, ...Object.entries(nestedConnection[1]).reduce>((res, [k, v]) => { - if (k !== `${relatedNodeVariable}_${connectionResolveTree.name}`) { + if (k !== `${relatedNodeVariable}_${connectionResolveTree.alias}`) { res[k] = v; } return res; }, {}), }; - if (nestedConnection[1][`${relatedNodeVariable}_${connectionResolveTree.name}`]) { + if (nestedConnection[1][`${relatedNodeVariable}_${connectionResolveTree.alias}`]) { if (!nestedConnectionFieldParams) nestedConnectionFieldParams = {}; nestedConnectionFieldParams = { ...nestedConnectionFieldParams, ...{ - [connectionResolveTree.name]: - nestedConnection[1][`${relatedNodeVariable}_${connectionResolveTree.name}`], + [connectionResolveTree.alias]: + nestedConnection[1][`${parameterPrefix}_${connectionResolveTree.alias}`], }, }; } @@ -403,7 +405,7 @@ function createConnectionAndParams({ const params = { ...globalParams, ...((whereInput || nestedConnectionFieldParams) && { - [`${nodeVariable}_${resolveTree.name}`]: { + [`${nodeVariable}_${resolveTree.alias}`]: { ...(whereInput && { args: { where: whereInput } }), ...(nestedConnectionFieldParams && { edges: { node: { ...nestedConnectionFieldParams } } }), }, From 07257fd623d010146c4f75479bb9812c55d39e0f Mon Sep 17 00:00:00 2001 From: dmoree Date: Thu, 5 Aug 2021 14:59:15 -0700 Subject: [PATCH 3/4] add: test for multiple aliases on connection --- .../integration/connections/alias.int.test.ts | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/packages/graphql/tests/integration/connections/alias.int.test.ts b/packages/graphql/tests/integration/connections/alias.int.test.ts index 4f40d6a1b6..4a1656e752 100644 --- a/packages/graphql/tests/integration/connections/alias.int.test.ts +++ b/packages/graphql/tests/integration/connections/alias.int.test.ts @@ -18,6 +18,7 @@ */ import { Driver } from "neo4j-driver"; +import faker from "faker"; import { graphql } from "graphql"; import { generate } from "randomstring"; import { gql } from "apollo-server"; @@ -858,4 +859,75 @@ describe("Connections Alias", () => { await session.close(); } }); + + test("should allow multiple aliases on the same connection", async () => { + const session = driver.session(); + + const typeDefs = gql` + type Post { + title: String! + comments: [Comment!]! @relationship(type: "HAS_COMMENT", direction: OUT) + } + + type Comment { + flag: Boolean! + post: Post! @relationship(type: "HAS_COMMENT", direction: IN) + } + `; + + const { schema } = new Neo4jGraphQL({ typeDefs }); + + const flags = new Array(faker.random.number({ min: 2, max: 5 })).map(() => faker.random.boolean()); + + const flaggedCount = flags.filter((flag) => flag).length; + const unflaggedCount = flags.filter((flag) => !flag).length; + + const query = ` + { + posts { + flagged: commentsConnection(where: { node: { flag: true } }) { + edges { + node { + flag + } + } + } + unflagged: commentsConnection(where: { node: { flag: false } }) { + edges { + node { + flag + } + } + } + } + } + `; + + try { + await session.run( + ` + CREATE (post:Post {title: "title"}) + FOREACH(flag in $flags | + CREATE (:Comment {flag: flag})<-[:HAS_COMMENT]-(post) + ) + `, + { + flags, + } + ); + + const result = await graphql({ + schema, + source: query, + contextValue: { driver, driverConfig: { bookmarks: [session.lastBookmark()] } }, + }); + + expect(result.errors).toBeUndefined(); + + expect((result.data as any).posts[0].flagged.edges).toHaveLength(flaggedCount); + expect((result.data as any).posts[0].unflagged.edges).toHaveLength(unflaggedCount); + } finally { + await session.close(); + } + }); }); From fa00796998645828f651676ed0d521fda323b716 Mon Sep 17 00:00:00 2001 From: dmoree Date: Thu, 5 Aug 2021 15:38:46 -0700 Subject: [PATCH 4/4] format: reformat to align with other tests --- .../tests/integration/connections/alias.int.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/graphql/tests/integration/connections/alias.int.test.ts b/packages/graphql/tests/integration/connections/alias.int.test.ts index 4a1656e752..da4382bff7 100644 --- a/packages/graphql/tests/integration/connections/alias.int.test.ts +++ b/packages/graphql/tests/integration/connections/alias.int.test.ts @@ -906,11 +906,11 @@ describe("Connections Alias", () => { try { await session.run( ` - CREATE (post:Post {title: "title"}) - FOREACH(flag in $flags | - CREATE (:Comment {flag: flag})<-[:HAS_COMMENT]-(post) - ) - `, + CREATE (post:Post {title: "title"}) + FOREACH(flag in $flags | + CREATE (:Comment {flag: flag})<-[:HAS_COMMENT]-(post) + ) + `, { flags, }