Skip to content

Commit

Permalink
Merge branch 'dev' into 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
angrykoala authored Jan 24, 2023
2 parents 1a8a1e0 + 7093c3d commit 9c8f83c
Show file tree
Hide file tree
Showing 87 changed files with 6,019 additions and 2,817 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-impalas-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/graphql": patch
---

fix: issue on generated Cypher with interface type (#2709)
5 changes: 5 additions & 0 deletions .changeset/thirty-bobcats-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/graphql": minor
---

Add `overwrite` argument on connect operation for relationships to standard types and arrays of
2 changes: 1 addition & 1 deletion .github/workflows/changesets-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:

- name: pull-request
if: steps.changesets.outputs.published == 'true'
uses: repo-sync/pull-request@65785d95a5a466e46a9d0708933a3bd51bbf9dde # renovate: tag=v2.6.2
uses: repo-sync/pull-request@7e79a9f5dc3ad0ce53138f01df2fad14a04831c5 # v2.12.1
with:
source_branch: "release/${{ github.sha }}"
destination_branch: "dev"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: reviewdog/action-actionlint@326cc761d95c903f29a111a44888be707f912684 # v1.35.0
- uses: reviewdog/action-actionlint@b6feb003955cad286985c42e7047f4567a798f3f # v1.36.0
with:
reporter: github-check
fail_on_error: true
2 changes: 1 addition & 1 deletion examples/neo-place/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@
},
"devDependencies": {
"concurrently": "7.6.0",
"parcel": "2.8.2"
"parcel": "2.8.3"
}
}
4 changes: 2 additions & 2 deletions examples/neo-push/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"react": "18.2.0",
"react-bootstrap": "2.7.0",
"react-dom": "18.2.0",
"react-markdown": "8.0.4",
"react-markdown": "8.0.5",
"react-mde": "11.5.0",
"react-router-dom": "6.6.2",
"react-router-dom": "6.7.0",
"showdown": "2.1.0",
"style-loader": "3.3.1",
"ts-loader": "9.4.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/neo-push/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@types/debug": "4.1.7",
"@types/dotenv": "8.2.0",
"@types/express": "4.17.15",
"@types/jest": "29.2.5",
"@types/jest": "29.2.6",
"@types/jsonwebtoken": "9.0.1",
"@types/node": "18.11.17",
"cross-env": "7.0.3",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@
},
"devDependencies": {
"@tsconfig/node16": "1.0.3",
"@typescript-eslint/eslint-plugin": "5.48.1",
"@typescript-eslint/parser": "5.48.1",
"@typescript-eslint/eslint-plugin": "5.48.2",
"@typescript-eslint/parser": "5.48.2",
"concurrently": "7.6.0",
"dotenv": "16.0.3",
"eslint": "8.32.0",
"eslint-config-prettier": "8.6.0",
"eslint-formatter-summary": "1.1.0",
"eslint-import-resolver-typescript": "3.5.3",
"eslint-plugin-eslint-comments": "3.2.0",
"eslint-plugin-import": "2.27.4",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jest": "27.2.1",
"eslint-plugin-jsx-a11y": "6.7.1",
"eslint-plugin-react": "7.32.0",
"eslint-plugin-react": "7.32.1",
"graphql": "16.6.0",
"husky": "8.0.3",
"jest": "29.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/cypher-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"homepage": "https://github.com/neo4j/graphql/tree/dev/packages/cypher-builder#readme",
"devDependencies": {
"@types/jest": "29.2.5",
"@types/jest": "29.2.6",
"@types/node": "18.11.17",
"expect-type": "0.15.0",
"jest": "29.3.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/graphql-toolbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
},
"author": "Neo4j",
"dependencies": {
"@neo4j-ndl/base": "0.16.0",
"@neo4j-ndl/react": "0.17.1",
"@neo4j-ndl/base": "0.16.1",
"@neo4j-ndl/react": "0.17.2",
"@neo4j/graphql": "3.14.2",
"@neo4j/introspector": "1.0.2",
"codemirror": "5.65.11",
"codemirror-graphql": "2.0.2",
"codemirror-graphql": "2.0.3",
"dotenv-webpack": "8.0.1",
"graphiql-explorer": "0.9.0",
"graphql": "16.6.0",
Expand All @@ -61,7 +61,7 @@
"devDependencies": {
"@playwright/test": "1.29.2",
"@tsconfig/create-react-app": "1.0.3",
"@types/codemirror": "5.60.6",
"@types/codemirror": "5.60.7",
"@types/lodash.debounce": "4.0.7",
"@types/markdown-it": "12.2.3",
"@types/prettier": "2.7.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@neo4j/graphql-plugin-auth": "^2.0.0",
"@types/deep-equal": "1.0.1",
"@types/is-uuid": "1.0.0",
"@types/jest": "29.2.5",
"@types/jest": "29.2.6",
"@types/jsonwebtoken": "9.0.1",
"@types/node": "18.11.17",
"@types/pluralize": "0.0.29",
Expand All @@ -76,7 +76,7 @@
"nock": "13.3.0",
"npm-run-all": "4.1.5",
"randomstring": "1.2.3",
"rimraf": "4.0.7",
"rimraf": "4.1.1",
"supertest": "6.3.3",
"ts-jest": "29.0.5",
"ts-node": "10.9.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { GraphQLBoolean } from "graphql";

export const overwrite = {
type: GraphQLBoolean,
description:
"Whether or not to overwrite any matching relationship with the new properties. Will default to `false` in 4.0.0.",
defaultValue: true,
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { FieldAggregationComposer } from "../aggregations/field-aggregation-comp
import { upperFirst } from "../../utils/upper-first";
import { addDirectedArgument } from "../directed-argument";
import { graphqlDirectivesToCompose } from "../to-compose";
import { overwrite } from "./fields/overwrite";

function createRelationshipFields({
relationshipFields,
Expand Down Expand Up @@ -758,7 +759,9 @@ function createRelationshipFields({
...(hasNonGeneratedProperties
? { edge: `${rel.properties}CreateInput${hasNonNullNonGeneratedProperties ? `!` : ""}` }
: {}),
overwrite,
});
tc.makeFieldNonNull("overwrite");
});

if (!rel.writeonly) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,13 @@ export class UnwindCreateVisitor implements Visitor {
return new Cypher.RawCypher((env: Cypher.Environment) => {
const authClauses = usedAuthFields
.map((authField) => {
const dbPropertyName = authField.dbPropertyName;
const [authCypher, authParams] = createAuthAndParams({
entity: authField,
operations: "CREATE",
context,
bind: {
parentNode: astNode.node,
varName: env.getReferenceId(nodeRef),
chainStr: `${env.getReferenceId(nodeRef)}_${dbPropertyName}`,
},
escapeQuotes: true,
});
Expand Down
3 changes: 0 additions & 3 deletions packages/graphql/src/translate/create-auth-and-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,16 @@ import { getOrCreateCypherNode } from "./utils/get-or-create-cypher-variable";
interface Allow {
varName: string | Cypher.Node;
parentNode: Node;
chainStr?: string;
}

interface Bind {
varName: string | Cypher.Node;
parentNode: Node;
chainStr?: string;
}

interface Where {
varName: string | Cypher.Node;
node: Node;
chainStr?: string;
}

export function createAuthAndParams({
Expand Down
15 changes: 15 additions & 0 deletions packages/graphql/src/translate/create-connect-and-params.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ describe("createConnectAndParams", () => {
}
RETURN count(*) AS _
}
WITH this, this0_node, this0_node_similarMovies0_node
CALL {
WITH this0_node
MATCH (this0_node)-[this0_node_similarMovies_Movie_unique:SIMILAR]->(other:Movie)
WITH count(this0_node_similarMovies_Movie_unique) as c, other
CALL apoc.util.validate(NOT (c = 1), '@neo4j/graphql/RELATIONSHIP-REQUIREDMovie.similarMovies required exactly once for a specific Movie', [0])
RETURN collect(c) AS this0_node_similarMovies_Movie_unique_ignored
}
CALL {
WITH this0_node_similarMovies0_node
MATCH (this0_node_similarMovies0_node)-[this0_node_similarMovies0_node_similarMovies_Movie_unique:SIMILAR]->(other:Movie)
WITH count(this0_node_similarMovies0_node_similarMovies_Movie_unique) as c, other
CALL apoc.util.validate(NOT (c = 1), '@neo4j/graphql/RELATIONSHIP-REQUIREDMovie.similarMovies required exactly once for a specific Movie', [0])
RETURN collect(c) AS this0_node_similarMovies0_node_similarMovies_Movie_unique_ignored
}
WITH this, this0_node, this0_node_similarMovies0_node
RETURN count(*) AS connect_this0_node_similarMovies_Movie
}
Expand Down
13 changes: 8 additions & 5 deletions packages/graphql/src/translate/create-connect-and-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function createConnectAndParams({
const relTypeStr = `[${relationField.properties || context.subscriptionsEnabled ? relationshipName : ""}:${
relationField.type
}]`;
const isOverwriteNotAllowed = connect.overwrite === false;

const subquery: string[] = [];
const labels = relatedNode.getLabelString(context);
Expand Down Expand Up @@ -187,7 +188,7 @@ function createConnectAndParams({
subquery.push(cypher);
} else {
subquery.push(`\tWHERE ${predicate}`);
}
}
}

const nodeMatrix: Array<{ node: Node; name: string }> = [{ node: relatedNode, name: nodeName }];
Expand All @@ -204,7 +205,7 @@ function createConnectAndParams({
operations: "CONNECT",
context,
escapeQuotes: Boolean(insideDoWhen),
allow: { parentNode: node, varName: name, chainStr: `${name}${node.name}${i}_allow` },
allow: { parentNode: node, varName: name },
});

if (!str) {
Expand Down Expand Up @@ -251,7 +252,8 @@ function createConnectAndParams({
subquery.push("\t\t\tWITH connectedNodes, parentNodes"); //
subquery.push(`\t\t\tUNWIND parentNodes as ${parentVar}`);
subquery.push(`\t\t\tUNWIND connectedNodes as ${nodeName}`);
subquery.push(`\t\t\tMERGE (${parentVar})${inStr}${relTypeStr}${outStr}(${nodeName})`);
const connectOperator = isOverwriteNotAllowed ? "CREATE" : "MERGE";
subquery.push(`\t\t\t${connectOperator} (${parentVar})${inStr}${relTypeStr}${outStr}(${nodeName})`);

if (relationField.properties) {
const relationship = context.relationships.find(
Expand Down Expand Up @@ -306,7 +308,7 @@ function createConnectAndParams({
innerMetaStr = `, connect_meta + meta AS meta`;
}

if (includeRelationshipValidation) {
if (includeRelationshipValidation || isOverwriteNotAllowed) {
const relValidationStrs: string[] = [];
const matrixItems = [
[parentNode, parentVar],
Expand All @@ -318,6 +320,7 @@ function createConnectAndParams({
node: mi[0],
context,
varName: mi[1],
relationshipFieldNotOverwritable: relationField.fieldName,
});
if (relValidationStr) {
relValidationStrs.push(relValidationStr);
Expand Down Expand Up @@ -466,7 +469,7 @@ function createConnectAndParams({
escapeQuotes: Boolean(insideDoWhen),
skipIsAuthenticated: true,
skipRoles: true,
bind: { parentNode: node, varName: nodeName, chainStr: `${nodeName}${node.name}${i}_bind` },
bind: { parentNode: node, varName: nodeName },
});

if (!str) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function createAuthStatement({
entity: node,
operations: ["CONNECT", "CREATE"],
context,
allow: { parentNode: node, varName: nodeName, chainStr: `${nodeName}${node.name}_allow` },
allow: { parentNode: node, varName: nodeName },
escapeQuotes: false,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/translate/create-create-and-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ function createCreateAndParams({
entity: primitiveField,
operations: "CREATE",
context,
bind: { parentNode: node, varName, chainStr: varNameKey },
bind: { parentNode: node, varName },
escapeQuotes: Boolean(insideDoWhen),
});
if (authAndParams[0]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function createDisconnectAndParams({
operations: "DISCONNECT",
context,
escapeQuotes: Boolean(insideDoWhen),
allow: { parentNode: node, varName: name, chainStr: `${name}${node.name}${i}_allow` },
allow: { parentNode: node, varName: name },
});

if (!str) {
Expand Down Expand Up @@ -356,7 +356,7 @@ function createDisconnectAndParams({
escapeQuotes: Boolean(insideDoWhen),
skipRoles: true,
skipIsAuthenticated: true,
bind: { parentNode: node, varName: variableName, chainStr: `${variableName}${node.name}${i}_bind` },
bind: { parentNode: node, varName: variableName },
});

if (!str) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function createProjectionAndParams({
entity: authableField,
operations: "READ",
context,
allow: { parentNode: node, varName, chainStr: param },
allow: { parentNode: node, varName },
});
if (allowAndParams[0]) {
if (!res.meta.authValidateStrs) {
Expand Down
Loading

0 comments on commit 9c8f83c

Please sign in to comment.