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

Remove nodes and relationships from the library's public API #3671

Merged
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
5 changes: 5 additions & 0 deletions .changeset/early-carrots-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/graphql": major
---

Remove `nodes` and `relationships` from the public API of the `Neo4jGraphQL` class.
5 changes: 5 additions & 0 deletions .changeset/orange-kings-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/graphql-ogm": major
---

Remove `nodes` from the public API of the `OGM` class.
32 changes: 16 additions & 16 deletions packages/graphql/src/classes/Neo4jGraphQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,6 @@ class Neo4jGraphQL {
}
}

public get nodes(): Node[] {
if (!this._nodes) {
throw new Error("You must await `.getSchema()` before accessing `nodes`");
}

return this._nodes;
}

public get relationships(): Relationship[] {
if (!this._relationships) {
throw new Error("You must await `.getSchema()` before accessing `relationships`");
}

return this._relationships;
}

public async getSchema(): Promise<GraphQLSchema> {
return this.getExecutableSchema();
}
Expand Down Expand Up @@ -264,6 +248,22 @@ class Neo4jGraphQL {
return { isValid: true, validationErrors: [] };
}

private get nodes(): Node[] {
if (!this._nodes) {
throw new Error("You must await `.getSchema()` before accessing `nodes`");
}

return this._nodes;
}

private get relationships(): Relationship[] {
if (!this._relationships) {
throw new Error("You must await `.getSchema()` before accessing `relationships`");
}

return this._relationships;
}

private addDefaultFieldResolvers(schema: GraphQLSchema): GraphQLSchema {
forEachField(schema, (field) => {
if (!field.resolve) {
Expand Down
7 changes: 1 addition & 6 deletions packages/graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import * as directives from "./graphql/directives";
import * as scalars from "./graphql/scalars";
const objects = { Point, CartesianPoint };

import { Neo4jGraphQLSubscriptionsMechanism, Node, SubscriptionsEvent } from "./types";
import { Neo4jGraphQLSubscriptionsMechanism, SubscriptionsEvent } from "./types";

/**
* Core library functionality.
Expand All @@ -38,11 +38,6 @@ export { Neo4jGraphQL, Neo4jGraphQLConstructor, Neo4jGraphQLContext };
*/
export { directives, scalars, objects };

/**
* Exports for usage by the OGM.
*/
export { Node };

/**
* Allows for the implementation of custom subscriptions mechanisms.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/src/translate/batch-create/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ describe("TreeDescriptor Parser", () => {
typeDefs,
});
schema = await neoSchema.getSchema();
nodes = neoSchema.nodes;
relationships = neoSchema.relationships;
nodes = neoSchema["nodes"];
relationships = neoSchema["relationships"];

movieNode = nodes.find((node) => node.name === "Movie") as unknown as Node;
context = new ContextBuilder({
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/tests/schema/issues/1614.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("https://github.com/neo4j/graphql/issues/1614", () => {
const errors = validateSchema(schema);
expect(errors).toEqual([]);

const relationship = neoSchema.relationships.find((r) => r.name === "CrewMemberMoviesRelationship");
const relationship = neoSchema["relationships"].find((r) => r.name === "CrewMemberMoviesRelationship");
expect(relationship).toBeDefined();
expect(relationship?.enumFields?.length).toBe(1);
expect(relationship?.properties).toBe("CrewPosition");
Expand Down
20 changes: 10 additions & 10 deletions packages/ogm/src/classes/OGM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/

import type { Neo4jGraphQLConstructor, Node } from "@neo4j/graphql";
import type { Neo4jGraphQLConstructor } from "@neo4j/graphql";
import { Neo4jGraphQL } from "@neo4j/graphql";
import type { GraphQLSchema } from "graphql";
import Model from "./Model";
Expand Down Expand Up @@ -106,14 +106,6 @@ class OGM<ModelMap = unknown> {
return this._schema;
}

public get nodes(): Node[] {
try {
return this.neoSchema.nodes;
} catch {
throw new Error("You must await `.init()` before accessing `nodes`");
}
}

public async init(): Promise<void> {
if (!this.initializer) {
this.initializer = this.createInitializer();
Expand Down Expand Up @@ -141,8 +133,16 @@ class OGM<ModelMap = unknown> {
return model as M;
}

private get nodes() {
try {
return this.neoSchema["nodes"];
} catch {
throw new Error("You must await `.init()` before accessing `nodes`");
}
}

private initModel(model: Model) {
const node = this.neoSchema.nodes.find((n) => n.name === model.name);
const node = this.neoSchema["nodes"].find((n) => n.name === model.name);

if (!node) {
throw new Error(`Could not find model ${model.name}`);
Expand Down
4 changes: 2 additions & 2 deletions packages/ogm/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function createAggregationInput({

function hasConnectOrCreate(node: any, ogm: OGM): boolean {
for (const relation of node.relationFields) {
const refNode = ogm.nodes.find((x) => x.name === relation.typeMeta.name);
const refNode = ogm["nodes"].find((x) => x.name === relation.typeMeta.name);
if (refNode && refNode.uniqueFields.length > 0) {
return true;
}
Expand Down Expand Up @@ -157,7 +157,7 @@ async function generate(options: IGenerateOptions): Promise<undefined | string>
const aggregateSelections: any = {};
const modeMap: Record<string, string> = {};

options.ogm.nodes.forEach((node) => {
options.ogm["nodes"].forEach((node) => {
const modelName = `${node.name}Model`;
const hasFulltextArg = Boolean(node.fulltextDirective);

Expand Down