Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General 2.0.0 housekeeping #255

Merged
merged 4 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
💡 Welcome to the Monorepo for [Neo4j](https://neo4j.com/) + [GraphQL](https://graphql.org/).

![Neo4j + GraphQL](./docs/images/banner.png)

<p align="center">
<a href="https://discord.gg/neo4j">
<img alt="Discord" src="https://img.shields.io/discord/787399249741479977?logo=discord&logoColor=white">
Expand All @@ -18,7 +19,7 @@ Want to contribute to `@neo4j/graphql`? See our [contributing guide](./docs/mark

## Links

1. [Documentation](https://neo4j.com/docs/graphql-manual/current/)
1. [Documentation](https://neo4j.com/docs/graphql-manual/2.0/)
2. [Discord](https://discord.gg/neo4j)
3. [Examples](./examples)

Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

A GraphQL to Cypher query execution layer for Neo4j and JavaScript GraphQL implementations.

1. [Documentation](https://neo4j.com/docs/graphql-manual/current/)
1. [Documentation](https://neo4j.com/docs/graphql-manual/2.0/)

## Installation

Expand Down
19 changes: 19 additions & 0 deletions packages/graphql/src/schema/get-relationship-field-meta.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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 { mergeTypeDefs } from "@graphql-tools/merge";
import { InterfaceTypeDefinitionNode } from "graphql";
import getRelationshipFieldMeta from "./get-relationship-field-meta";
Expand Down
26 changes: 19 additions & 7 deletions packages/graphql/src/schema/get-where-fields.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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 { CustomEnumField, CustomScalarField, DateTimeField, PointField, PrimitiveField } from "../types";

interface Fields {
Expand All @@ -19,13 +38,6 @@ function getWhereFields({ typeName, fields, enableRegex }: { typeName: string; f
}, {}),
...[...fields.primitiveFields, ...fields.dateTimeFields, ...fields.enumFields, ...fields.pointFields].reduce(
(res, f) => {
// This is the only sensible place to flag whether Point and CartesianPoint are used
// if (f.typeMeta.name === "Point") {
// pointInTypeDefs = true;
// } else if (f.typeMeta.name === "CartesianPoint") {
// cartesianPointInTypeDefs = true;
// }

res[f.fieldName] = f.typeMeta.input.where.pretty;
res[`${f.fieldName}_NOT`] = f.typeMeta.input.where.pretty;

Expand Down
32 changes: 2 additions & 30 deletions packages/graphql/src/schema/make-augmented-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function makeAugmentedSchema(

composer.createInputTC({
name: `${relationship.name.value}CreateInput`,
// TODO - Duplicated with rel properties
// TODO - This reduce duplicated when creating node CreateInput - put into shared function?
fields: relationshipFieldMeta.reduce((res, f) => {
if ((f as PrimitiveField)?.autogenerate) {
return res;
Expand Down Expand Up @@ -489,7 +489,7 @@ function makeAugmentedSchema(

const nodeInput = composer.createInputTC({
name: `${node.name}CreateInput`,
// TODO - Duplicated with rel properties
// TODO - This reduce duplicated when creating relationship CreateInput - put into shared function?
fields: [
...node.primitiveFields,
...node.scalarFields,
Expand Down Expand Up @@ -573,24 +573,6 @@ function makeAugmentedSchema(
},
});

// composer.createInputTC({
// name: `${node.name}DisconnectFieldInput`,
// fields: {
// where: `${node.name}Where`,
// ...(node.relationFields.length ? { disconnect: nodeDisconnectInput } : {}),
// },
// });

// if (!composer.has(`${node.name}DeleteFieldInput`)) {
// composer.createInputTC({
// name: `${node.name}DeleteFieldInput`,
// fields: {
// where: `${node.name}Where`,
// ...(node.relationFields.length ? { delete: nodeDeleteInput } : {}),
// },
// });
// }

node.relationFields.forEach((rel) => {
if (rel.union) {
const refNodes = nodes.filter((x) => rel.union?.nodes?.includes(x.name));
Expand All @@ -614,13 +596,6 @@ function makeAugmentedSchema(
const nodeFieldDeleteInputName = `${unionPrefix}DeleteFieldInput`;
const nodeFieldDisconnectInputName = `${unionPrefix}DisconnectFieldInput`;

// const disconnectField = rel.typeMeta.array
// ? `[${n.name}DisconnectFieldInput!]`
// : `${n.name}DisconnectFieldInput`;
// const deleteField = rel.typeMeta.array
// ? `[${n.name}DeleteFieldInput!]`
// : `${n.name}DeleteFieldInput`;

composeNode.addFieldArgs(rel.fieldName, {
[n.name]: `${n.name}Where`,
});
Expand Down Expand Up @@ -760,9 +735,6 @@ function makeAugmentedSchema(
const nodeFieldUpdateInputName = `${node.name}${upperFirstLetter(rel.fieldName)}UpdateFieldInput`;
const nodeFieldDeleteInputName = `${node.name}${upperFirstLetter(rel.fieldName)}DeleteFieldInput`;
const nodeFieldDisconnectInputName = `${node.name}${upperFirstLetter(rel.fieldName)}DisconnectFieldInput`;
// const disconnectField = rel.typeMeta.array
// ? `[${n.name}DisconnectFieldInput!]`
// : `${n.name}DisconnectFieldInput`;

whereInput.addFields({
...{ [rel.fieldName]: `${n.name}Where`, [`${rel.fieldName}_NOT`]: `${n.name}Where` },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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 { ResolveTree } from "graphql-parse-resolve-info";
import dedent from "dedent";
import { mocked } from "ts-jest/utils";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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 { FieldsByTypeName, ResolveTree } from "graphql-parse-resolve-info";
import { ConnectionField, ConnectionOptionsArg, ConnectionWhereArg, Context } from "../../types";
import { Node } from "../../classes";
Expand All @@ -6,54 +25,6 @@ import Relationship from "../../classes/Relationship";
import createRelationshipPropertyElement from "../projection/elements/create-relationship-property-element";
import createConnectionWhereAndParams from "../where/create-connection-where-and-params";

/*
input:

{
actorsConnection: {
alias: "actorsConnection"
name: "actorsConnection"
args: { where, options }????
fieldsByTypeName: {
MovieActorsConnection: {
edges: {
alias: "edges"
name: "edges"
args: { }
fieldsByTypeName: {
MovieActorsRelationship: {
screenTime: {
alias: "screenTime"
name: "screenTime"
}
node: {
alias: "node"
name: "node"
fieldsByTypeName: { PASS ME BACK TO create-projection-and-params
..........
}
}
}
}
}
}
}
}
}

output:

actorsConnection: apoc.cypher.runFirstColumn(
"
MATCH (this)<-[this_acted_in:ACTED_IN]-(this_actors:Actor)
WITH collect({ screenTime: this_acted_in.screenTime, node: { name: this_actors.name }}) as edges
RETURN { edges: edges }
",
{this: this},
true
)

*/
function createConnectionAndParams({
resolveTree,
field,
Expand Down Expand Up @@ -212,11 +183,6 @@ function createConnectionAndParams({
const nodeOutStr = `(${relatedNodeVariable}:${field.relationship.typeMeta.name})`;
const relatedNode = context.neoSchema.nodes.find((x) => x.name === field.relationship.typeMeta.name) as Node;

/*
MATCH clause, example:

MATCH (this)<-[this_acted_in:ACTED_IN]-(this_actor:Actor)
*/
subquery.push(`MATCH (${nodeVariable})${inStr}${relTypeStr}${outStr}${nodeOutStr}`);

if (whereInput) {
Expand Down
4 changes: 1 addition & 3 deletions packages/graphql/src/translate/create-delete-and-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,11 @@ function createDeleteAndParams({
relationshipVariable,
relationship,
parameterPrefix: `${parameterPrefix}${!recursing ? `.${key}` : ""}${
// used here
relationField.typeMeta.array ? `[${index}]` : ""
}.where`,
});
if (whereAndParams[0]) {
whereStrs.push(whereAndParams[0]);
// res.params = { ...res.params, ...whereAndParams[1] };
}
}
const whereAuth = createAuthAndParams({
Expand Down Expand Up @@ -145,7 +143,7 @@ function createDeleteAndParams({
parentVar: _varName,
parameterPrefix: `${parameterPrefix}${!recursing ? `.${key}` : ""}${
relationField.typeMeta.array ? `[${index}]` : ""
}.delete`, // TODO
}.delete`,
recursing: false,
});
res.strs.push(deleteAndParams[0]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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.
*/

/* eslint-disable prefer-destructuring */
import { Relationship } from "../classes";
import { BaseField, DateTimeField, PrimitiveField } from "../types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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 { Relationship } from "../classes";
import { BaseField, DateTimeField, PrimitiveField } from "../types";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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 { ResolveTree } from "graphql-parse-resolve-info";
import { DateTimeField } from "../../../types";
import createDatetimeElement from "./create-datetime-element";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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 { ResolveTree } from "graphql-parse-resolve-info";
import { DateTimeField } from "../../../types";

Expand Down
Loading