diff --git a/.changeset/early-carrots-scream.md b/.changeset/early-carrots-scream.md new file mode 100644 index 0000000000..547acdd693 --- /dev/null +++ b/.changeset/early-carrots-scream.md @@ -0,0 +1,5 @@ +--- +"@neo4j/graphql": major +--- + +Remove `nodes` and `relationships` from the public API of the `Neo4jGraphQL` class. diff --git a/.changeset/orange-kings-turn.md b/.changeset/orange-kings-turn.md new file mode 100644 index 0000000000..0ab4678bec --- /dev/null +++ b/.changeset/orange-kings-turn.md @@ -0,0 +1,5 @@ +--- +"@neo4j/graphql-ogm": major +--- + +Remove `nodes` from the public API of the `OGM` class. diff --git a/packages/graphql/src/classes/Neo4jGraphQL.ts b/packages/graphql/src/classes/Neo4jGraphQL.ts index 988b2404a6..5567b14428 100644 --- a/packages/graphql/src/classes/Neo4jGraphQL.ts +++ b/packages/graphql/src/classes/Neo4jGraphQL.ts @@ -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 { return this.getExecutableSchema(); } @@ -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) { diff --git a/packages/graphql/src/index.ts b/packages/graphql/src/index.ts index 60928729cf..a4980d0fe9 100644 --- a/packages/graphql/src/index.ts +++ b/packages/graphql/src/index.ts @@ -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. @@ -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. */ diff --git a/packages/graphql/src/translate/batch-create/parser.test.ts b/packages/graphql/src/translate/batch-create/parser.test.ts index 88299c5380..16ef7deb7c 100644 --- a/packages/graphql/src/translate/batch-create/parser.test.ts +++ b/packages/graphql/src/translate/batch-create/parser.test.ts @@ -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({ diff --git a/packages/graphql/tests/schema/issues/1614.test.ts b/packages/graphql/tests/schema/issues/1614.test.ts index 54594683d7..bb5ea36ad3 100644 --- a/packages/graphql/tests/schema/issues/1614.test.ts +++ b/packages/graphql/tests/schema/issues/1614.test.ts @@ -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"); diff --git a/packages/ogm/src/classes/OGM.ts b/packages/ogm/src/classes/OGM.ts index b6f7b3dfef..13fbfe3a8b 100644 --- a/packages/ogm/src/classes/OGM.ts +++ b/packages/ogm/src/classes/OGM.ts @@ -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"; @@ -106,14 +106,6 @@ class OGM { 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 { if (!this.initializer) { this.initializer = this.createInitializer(); @@ -141,8 +133,16 @@ class OGM { 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}`); diff --git a/packages/ogm/src/generate.ts b/packages/ogm/src/generate.ts index a21493b3e3..35f5ec149e 100644 --- a/packages/ogm/src/generate.ts +++ b/packages/ogm/src/generate.ts @@ -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; } @@ -157,7 +157,7 @@ async function generate(options: IGenerateOptions): Promise const aggregateSelections: any = {}; const modeMap: Record = {}; - options.ogm.nodes.forEach((node) => { + options.ogm["nodes"].forEach((node) => { const modelName = `${node.name}Model`; const hasFulltextArg = Boolean(node.fulltextDirective);