Skip to content

Commit b3951fa

Browse files
authored
Remove nodes and relationships from the library's public API (#3671)
* Remove `nodes` and `relationships` from the library's public API * Fix bad merge
1 parent 5ea1813 commit b3951fa

File tree

8 files changed

+42
-37
lines changed

8 files changed

+42
-37
lines changed

.changeset/early-carrots-scream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@neo4j/graphql": major
3+
---
4+
5+
Remove `nodes` and `relationships` from the public API of the `Neo4jGraphQL` class.

.changeset/orange-kings-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@neo4j/graphql-ogm": major
3+
---
4+
5+
Remove `nodes` from the public API of the `OGM` class.

packages/graphql/src/classes/Neo4jGraphQL.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,6 @@ class Neo4jGraphQL {
130130
}
131131
}
132132

133-
public get nodes(): Node[] {
134-
if (!this._nodes) {
135-
throw new Error("You must await `.getSchema()` before accessing `nodes`");
136-
}
137-
138-
return this._nodes;
139-
}
140-
141-
public get relationships(): Relationship[] {
142-
if (!this._relationships) {
143-
throw new Error("You must await `.getSchema()` before accessing `relationships`");
144-
}
145-
146-
return this._relationships;
147-
}
148-
149133
public async getSchema(): Promise<GraphQLSchema> {
150134
return this.getExecutableSchema();
151135
}
@@ -264,6 +248,22 @@ class Neo4jGraphQL {
264248
return { isValid: true, validationErrors: [] };
265249
}
266250

251+
private get nodes(): Node[] {
252+
if (!this._nodes) {
253+
throw new Error("You must await `.getSchema()` before accessing `nodes`");
254+
}
255+
256+
return this._nodes;
257+
}
258+
259+
private get relationships(): Relationship[] {
260+
if (!this._relationships) {
261+
throw new Error("You must await `.getSchema()` before accessing `relationships`");
262+
}
263+
264+
return this._relationships;
265+
}
266+
267267
private addDefaultFieldResolvers(schema: GraphQLSchema): GraphQLSchema {
268268
forEachField(schema, (field) => {
269269
if (!field.resolve) {

packages/graphql/src/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import * as directives from "./graphql/directives";
2626
import * as scalars from "./graphql/scalars";
2727
const objects = { Point, CartesianPoint };
2828

29-
import { Neo4jGraphQLSubscriptionsMechanism, Node, SubscriptionsEvent } from "./types";
29+
import { Neo4jGraphQLSubscriptionsMechanism, SubscriptionsEvent } from "./types";
3030

3131
/**
3232
* Core library functionality.
@@ -38,11 +38,6 @@ export { Neo4jGraphQL, Neo4jGraphQLConstructor, Neo4jGraphQLContext };
3838
*/
3939
export { directives, scalars, objects };
4040

41-
/**
42-
* Exports for usage by the OGM.
43-
*/
44-
export { Node };
45-
4641
/**
4742
* Allows for the implementation of custom subscriptions mechanisms.
4843
*/

packages/graphql/src/translate/batch-create/parser.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ describe("TreeDescriptor Parser", () => {
6868
typeDefs,
6969
});
7070
schema = await neoSchema.getSchema();
71-
nodes = neoSchema.nodes;
72-
relationships = neoSchema.relationships;
71+
nodes = neoSchema["nodes"];
72+
relationships = neoSchema["relationships"];
7373

7474
movieNode = nodes.find((node) => node.name === "Movie") as unknown as Node;
7575
context = new ContextBuilder({

packages/graphql/tests/schema/issues/1614.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe("https://github.com/neo4j/graphql/issues/1614", () => {
5151
const errors = validateSchema(schema);
5252
expect(errors).toEqual([]);
5353

54-
const relationship = neoSchema.relationships.find((r) => r.name === "CrewMemberMoviesRelationship");
54+
const relationship = neoSchema["relationships"].find((r) => r.name === "CrewMemberMoviesRelationship");
5555
expect(relationship).toBeDefined();
5656
expect(relationship?.enumFields?.length).toBe(1);
5757
expect(relationship?.properties).toBe("CrewPosition");

packages/ogm/src/classes/OGM.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* limitations under the License.
1818
*/
1919

20-
import type { Neo4jGraphQLConstructor, Node } from "@neo4j/graphql";
20+
import type { Neo4jGraphQLConstructor } from "@neo4j/graphql";
2121
import { Neo4jGraphQL } from "@neo4j/graphql";
2222
import type { GraphQLSchema } from "graphql";
2323
import Model from "./Model";
@@ -106,14 +106,6 @@ class OGM<ModelMap = unknown> {
106106
return this._schema;
107107
}
108108

109-
public get nodes(): Node[] {
110-
try {
111-
return this.neoSchema.nodes;
112-
} catch {
113-
throw new Error("You must await `.init()` before accessing `nodes`");
114-
}
115-
}
116-
117109
public async init(): Promise<void> {
118110
if (!this.initializer) {
119111
this.initializer = this.createInitializer();
@@ -141,8 +133,16 @@ class OGM<ModelMap = unknown> {
141133
return model as M;
142134
}
143135

136+
private get nodes() {
137+
try {
138+
return this.neoSchema["nodes"];
139+
} catch {
140+
throw new Error("You must await `.init()` before accessing `nodes`");
141+
}
142+
}
143+
144144
private initModel(model: Model) {
145-
const node = this.neoSchema.nodes.find((n) => n.name === model.name);
145+
const node = this.neoSchema["nodes"].find((n) => n.name === model.name);
146146

147147
if (!node) {
148148
throw new Error(`Could not find model ${model.name}`);

packages/ogm/src/generate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function createAggregationInput({
122122

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

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

0 commit comments

Comments
 (0)