Skip to content

Commit

Permalink
Merge pull request #643 from angrykoala/Fix/revert-572-non-nullable-c…
Browse files Browse the repository at this point in the history
…hecks

Reverts #572 non nullable relation checks
  • Loading branch information
angrykoala authored Dec 15, 2021
2 parents 1261040 + 1e39592 commit 6c9be5b
Show file tree
Hide file tree
Showing 29 changed files with 121 additions and 546 deletions.
10 changes: 0 additions & 10 deletions packages/graphql/src/classes/Error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ export class Neo4jGraphQLConstraintValidationError extends Neo4jGraphQLError {
}
}

export class Neo4jGraphQLRelationshipValidationError extends Neo4jGraphQLError {
readonly name;

constructor(message: string) {
super(message);

Object.defineProperty(this, "name", { value: "Neo4jGraphQLRelationshipValidationError" });
}
}

export class Neo4jGraphQLCypherBuilderError extends Neo4jGraphQLError {
readonly name;

Expand Down
1 change: 0 additions & 1 deletion packages/graphql/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const DEBUG_PREFIX = "@neo4j/graphql";

export const AUTH_FORBIDDEN_ERROR = "@neo4j/graphql/FORBIDDEN";
export const AUTH_UNAUTHENTICATED_ERROR = "@neo4j/graphql/UNAUTHENTICATED";
export const RELATIONSHIP_REQUIREMENT_PREFIX = "@neo4j/graphql/RELATIONSHIP-REQUIRED";
export const MIN_VERSIONS = [
{ majorMinor: "4.1", neo4j: "4.1.5" },
{ majorMinor: "4.2", neo4j: "4.2.9" },
Expand Down
1 change: 0 additions & 1 deletion packages/graphql/src/schema/get-field-type-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ function getFieldTypeMeta(field: FieldDefinitionNode | InputValueDefinitionNode)
required,
pretty,
arrayTypePretty,
arrayTypeRequired,
};

const isPoint = ["Point", "CartesianPoint"].includes(name);
Expand Down
7 changes: 0 additions & 7 deletions packages/graphql/src/translate/create-create-and-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import createAuthAndParams from "./create-auth-and-params";
import { AUTH_FORBIDDEN_ERROR } from "../constants";
import createSetRelationshipPropertiesAndParams from "./create-set-relationship-properties-and-params";
import mapToDbProperty from "../utils/map-to-db-property";
import createRelationshipValidationStr from "./create-relationship-validation-str";
import { createConnectOrCreateAndParams } from "./connect-or-create/create-connect-or-create-and-params";

interface Res {
Expand Down Expand Up @@ -260,12 +259,6 @@ function createCreateAndParams({
creates.push(`CALL apoc.util.validate(NOT(${meta.authStrs.join(" AND ")}), ${forbiddenString}, [0])`);
}

const relationshipValidationStr = createRelationshipValidationStr({ node, context, varName });
if (relationshipValidationStr) {
creates.push(`WITH ${withVars.join(", ")}`);
creates.push(relationshipValidationStr);
}

return [creates.join("\n"), params];
}

Expand Down

This file was deleted.

16 changes: 3 additions & 13 deletions packages/graphql/src/translate/create-update-and-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import createSetRelationshipProperties from "./create-set-relationship-propertie
import createConnectionWhereAndParams from "./where/create-connection-where-and-params";
import mapToDbProperty from "../utils/map-to-db-property";
import { createConnectOrCreateAndParams } from "./connect-or-create/create-connect-or-create-and-params";
import createRelationshipValidationStr from "./create-relationship-validation-str";
import { wrapInCall } from "./utils/wrap-in-call";

interface Res {
Expand All @@ -54,7 +53,6 @@ function createUpdateAndParams({
withVars,
context,
parameterPrefix,
fromTopLevel,
}: {
parentVar: string;
updateInput: any;
Expand All @@ -65,7 +63,6 @@ function createUpdateAndParams({
insideDoWhen?: boolean;
context: Context;
parameterPrefix: string;
fromTopLevel?: boolean;
}): [string, any] {
let hasAppliedTimeStamps = false;

Expand Down Expand Up @@ -528,7 +525,6 @@ function createUpdateAndParams({

let preAuthStr = "";
let postAuthStr = "";
const relationshipValidationStr = !fromTopLevel ? createRelationshipValidationStr({ node, context, varName }) : "";

const forbiddenString = insideDoWhen ? `\\"${AUTH_FORBIDDEN_ERROR}\\"` : `"${AUTH_FORBIDDEN_ERROR}"`;

Expand All @@ -542,15 +538,9 @@ function createUpdateAndParams({
postAuthStr = `${withStr}\n${apocStr}`;
}

return [
[
preAuthStr,
...strs,
postAuthStr,
...(relationshipValidationStr ? [withStr, relationshipValidationStr] : []),
].join("\n"),
params,
];
const str = `${preAuthStr}\n${strs.join("\n")}\n${postAuthStr}`;

return [str, params];
}

export default createUpdateAndParams;
5 changes: 0 additions & 5 deletions packages/graphql/src/translate/translate-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import createConnectionAndParams from "./connection/create-connection-and-params
import createSetRelationshipPropertiesAndParams from "./create-set-relationship-properties-and-params";
import createInterfaceProjectionAndParams from "./create-interface-projection-and-params";
import translateTopLevelMatch from "./translate-top-level-match";
import createRelationshipValidationStr from "./create-relationship-validation-str";
import { createConnectOrCreateAndParams } from "./connect-or-create/create-connect-or-create-and-params";

function translateUpdate({ node, context }: { node: Node; context: Context }): [string, any] {
Expand Down Expand Up @@ -77,7 +76,6 @@ function translateUpdate({ node, context }: { node: Node; context: Context }): [
parentVar: varName,
withVars: [varName],
parameterPrefix: `${resolveTree.name}.args.update`,
fromTopLevel: true,
});
[updateStr] = updateAndParams;
cypherParams = {
Expand Down Expand Up @@ -385,8 +383,6 @@ function translateUpdate({ node, context }: { node: Node; context: Context }): [
}
}

const relationshipValidationStr = createRelationshipValidationStr({ node, context, varName });

const returnStatement = nodeProjection
? `RETURN ${varName} ${projStr} AS ${varName}`
: `RETURN 'Query cannot conclude with CALL'`;
Expand All @@ -400,7 +396,6 @@ function translateUpdate({ node, context }: { node: Node; context: Context }): [
deleteStr,
...(connectionStrs.length || projAuth ? [`WITH ${varName}`] : []), // When FOREACH is the last line of update 'Neo4jError: WITH is required between FOREACH and CALL'
...(projAuth ? [projAuth] : []),
...(relationshipValidationStr ? [`WITH ${varName}`, relationshipValidationStr] : []),
...connectionStrs,
...interfaceStrs,
returnStatement,
Expand Down
1 change: 0 additions & 1 deletion packages/graphql/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export interface TypeMeta {
pretty: string;
};
};
arrayTypeRequired?: boolean;
}

export interface Unique {
Expand Down
13 changes: 1 addition & 12 deletions packages/graphql/src/utils/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ import {
Neo4jGraphQLForbiddenError,
Neo4jGraphQLAuthenticationError,
Neo4jGraphQLConstraintValidationError,
Neo4jGraphQLRelationshipValidationError,
} from "../classes";
import {
AUTH_FORBIDDEN_ERROR,
AUTH_UNAUTHENTICATED_ERROR,
DEBUG_EXECUTE,
RELATIONSHIP_REQUIREMENT_PREFIX,
} from "../constants";
import { AUTH_FORBIDDEN_ERROR, AUTH_UNAUTHENTICATED_ERROR, DEBUG_EXECUTE } from "../constants";
import createAuthParam from "../translate/create-auth-param";
import { Context, DriverConfig } from "../types";
import environment from "../environment";
Expand Down Expand Up @@ -127,11 +121,6 @@ async function execute(input: {
throw new Neo4jGraphQLAuthenticationError("Unauthenticated");
}

if (error.message.includes(`Caused by: java.lang.RuntimeException: ${RELATIONSHIP_REQUIREMENT_PREFIX}`)) {
const [, message] = error.message.split(RELATIONSHIP_REQUIREMENT_PREFIX);
throw new Neo4jGraphQLRelationshipValidationError(message);
}

if (error.code === "Neo.ClientError.Schema.ConstraintValidationFailed") {
throw new Neo4jGraphQLConstraintValidationError("Constraint validation failed");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ describe("interface relationships", () => {
const typeDefs = gql`
type Episode {
runtime: Int!
series: Series @relationship(type: "HAS_EPISODE", direction: IN)
series: Series! @relationship(type: "HAS_EPISODE", direction: IN)
}
interface Production {
title: String!
actors: [Actor] @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
}
type Movie implements Production {
title: String!
runtime: Int!
actors: [Actor] @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
}
type Series implements Production {
title: String!
episodes: [Episode] @relationship(type: "HAS_EPISODE", direction: OUT)
actors: [Actor] @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
episodes: [Episode!]! @relationship(type: "HAS_EPISODE", direction: OUT)
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
}
interface ActedIn @relationshipProperties {
Expand All @@ -61,7 +61,7 @@ describe("interface relationships", () => {
type Actor {
name: String!
actedIn: [Production] @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
actedIn: [Production!]! @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
}
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,34 @@ describe("interface relationships", () => {

const typeDefs = gql`
type Episode {
runtime: Int
series: Series @relationship(type: "HAS_EPISODE", direction: IN)
runtime: Int!
series: Series! @relationship(type: "HAS_EPISODE", direction: IN)
}
interface Production {
title: String
actors: [Actor] @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
title: String!
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
}
type Movie implements Production {
title: String
runtime: Int
actors: [Actor] @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
title: String!
runtime: Int!
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
}
type Series implements Production {
title: String
episodes: [Episode] @relationship(type: "HAS_EPISODE", direction: OUT)
actors: [Actor] @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
title: String!
episodes: [Episode!]! @relationship(type: "HAS_EPISODE", direction: OUT)
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
}
interface ActedIn @relationshipProperties {
screenTime: Int
screenTime: Int!
}
type Actor {
name: String
actedIn: [Production] @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
name: String!
actedIn: [Production!]! @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
}
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ describe("interface relationships", () => {
const typeDefs = gql`
type Episode {
runtime: Int!
series: Series @relationship(type: "HAS_EPISODE", direction: IN)
series: Series! @relationship(type: "HAS_EPISODE", direction: IN)
}
interface Production {
title: String!
actors: [Actor] @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
}
type Movie implements Production {
title: String!
runtime: Int!
actors: [Actor] @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
}
type Series implements Production {
title: String!
episodes: [Episode] @relationship(type: "HAS_EPISODE", direction: OUT)
actors: [Actor] @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
episodes: [Episode!]! @relationship(type: "HAS_EPISODE", direction: OUT)
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
}
interface ActedIn @relationshipProperties {
Expand All @@ -61,7 +61,7 @@ describe("interface relationships", () => {
type Actor {
name: String!
actedIn: [Production] @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
actedIn: [Production!]! @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
}
`;

Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/tests/integration/issues/247.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ describe("https://github.com/neo4j/graphql/issues/247", () => {
const typeDefs = gql`
type Movie {
title: String!
owners: [User] @relationship(type: "OWNS", direction: IN)
owners: [User!]! @relationship(type: "OWNS", direction: IN)
}
type User {
name: String!
movies: [Movie] @relationship(type: "OWNS", direction: OUT)
movies: [Movie!]! @relationship(type: "OWNS", direction: OUT)
}
`;

Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/tests/integration/issues/315.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe("https://github.com/neo4j/graphql/issues/315", () => {
type User {
id: ID!
friends: [User] @relationship(type: "HAS_FRIEND", direction: OUT)
posts: [Post] @relationship(type: "HAS_POST", direction: OUT)
friends: [User!]! @relationship(type: "HAS_FRIEND", direction: OUT)
posts: [Post!]! @relationship(type: "HAS_POST", direction: OUT)
}
type Query {
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/tests/integration/issues/388.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe("https://github.com/neo4j/graphql/issues/388", () => {
type User {
id: ID!
friends: [User] @relationship(type: "HAS_FRIEND", direction: OUT)
posts: [Post] @relationship(type: "HAS_POST", direction: OUT)
friends: [User!]! @relationship(type: "HAS_FRIEND", direction: OUT)
posts: [Post!]! @relationship(type: "HAS_POST", direction: OUT)
}
type Query {
Expand Down
Loading

0 comments on commit 6c9be5b

Please sign in to comment.