diff --git a/.changeset/loud-rivers-wonder.md b/.changeset/loud-rivers-wonder.md new file mode 100644 index 0000000000..fe554639fe --- /dev/null +++ b/.changeset/loud-rivers-wonder.md @@ -0,0 +1,5 @@ +--- +"@neo4j/graphql": major +--- + +Removal of the following exports: `Neo4jGraphQLAuthenticationError`, `Neo4jGraphQLForbiddenError`, `EventMeta`, `Neo4jGraphQLAuthPlugin` and `RelationField`. This are either redundant, or internals which shouldn't have been exported. diff --git a/packages/graphql/src/classes/Neo4jGraphQL.ts b/packages/graphql/src/classes/Neo4jGraphQL.ts index e52c8f8ce0..d4188dcb60 100644 --- a/packages/graphql/src/classes/Neo4jGraphQL.ts +++ b/packages/graphql/src/classes/Neo4jGraphQL.ts @@ -21,7 +21,6 @@ import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge"; import Debug from "debug"; import type { CypherQueryOptions, - Neo4jGraphQLPlugins, Neo4jFeaturesSettings, StartupValidationConfig, ContextFeatures, @@ -75,7 +74,6 @@ export interface Neo4jGraphQLConstructor { features?: Neo4jFeaturesSettings; config?: Neo4jGraphQLConfig; driver?: Driver; - plugins?: Neo4jGraphQLPlugins; } export const defaultValidationConfig: ValidationConfig = { @@ -94,7 +92,6 @@ class Neo4jGraphQL { private _nodes?: Node[]; private _relationships?: Relationship[]; - private plugins?: Neo4jGraphQLPlugins; private jwtFieldsMap?: Map; @@ -111,11 +108,10 @@ class Neo4jGraphQL { private authorization?: Neo4jGraphQLAuthorization; constructor(input: Neo4jGraphQLConstructor) { - const { config = {}, driver, plugins, features, typeDefs, resolvers } = input; + const { config = {}, driver, features, typeDefs, resolvers } = input; this.driver = driver; this.config = config; - this.plugins = plugins; this.features = this.parseNeo4jFeatures(features); this.typeDefs = typeDefs; @@ -313,7 +309,6 @@ class Neo4jGraphQL { nodes: this.nodes, relationships: this.relationships, schemaModel: this.schemaModel, - plugins: this.plugins, features: this.features, authorization: this.authorization, jwtPayloadFieldsMap: this.jwtFieldsMap, diff --git a/packages/graphql/src/index.ts b/packages/graphql/src/index.ts index 2e2961d4cc..d0ec906502 100644 --- a/packages/graphql/src/index.ts +++ b/packages/graphql/src/index.ts @@ -17,30 +17,41 @@ * limitations under the License. */ +import { Neo4jGraphQL, Neo4jGraphQLConstructor } from "./classes"; +import { Neo4jGraphQLContext } from "./types/neo4j-graphql-context"; + import { CartesianPoint } from "./graphql/objects/CartesianPoint"; import { Point } from "./graphql/objects/Point"; +import * as directives from "./graphql/directives"; +import * as scalars from "./graphql/scalars"; +const objects = { Point, CartesianPoint }; -export { - Neo4jGraphQL, - Neo4jGraphQLAuthenticationError, - Neo4jGraphQLConstructor, - Neo4jGraphQLForbiddenError, -} from "./classes"; -export * as directives from "./graphql/directives"; -export * as scalars from "./graphql/scalars"; -export { +import { DeleteInfo, - EventMeta, GraphQLOptionsArg, GraphQLSortArg, GraphQLWhereArg, - Neo4jGraphQLAuthPlugin, Neo4jGraphQLSubscriptionsMechanism, Node, - RelationField, SubscriptionsEvent, } from "./types"; -export { Neo4jGraphQLContext } from "./types/neo4j-graphql-context"; +/** + * Core library functionality. + */ +export { Neo4jGraphQL, Neo4jGraphQLConstructor, Neo4jGraphQLContext }; + +/** + * Library built-in GraphQL types. + */ +export { directives, scalars, objects }; -export const objects = { Point, CartesianPoint }; +/** + * Exports for usage by the OGM. + */ +export { DeleteInfo, GraphQLOptionsArg, GraphQLSortArg, GraphQLWhereArg, Node }; + +/** + * Allows for the implementation of custom subscriptions mechanisms. + */ +export { Neo4jGraphQLSubscriptionsMechanism, SubscriptionsEvent }; diff --git a/packages/graphql/src/schema/resolvers/wrapper.ts b/packages/graphql/src/schema/resolvers/wrapper.ts index 6c879ecf8a..14050eca63 100644 --- a/packages/graphql/src/schema/resolvers/wrapper.ts +++ b/packages/graphql/src/schema/resolvers/wrapper.ts @@ -28,7 +28,7 @@ import { getNeo4jDatabaseInfo } from "../../classes/Neo4jDatabaseInfo"; import { Executor } from "../../classes/Executor"; import type { ExecutorConstructorParam } from "../../classes/Executor"; import { AUTH_FORBIDDEN_ERROR, DEBUG_GRAPHQL } from "../../constants"; -import type { Context, ContextFeatures, Neo4jGraphQLPlugins } from "../../types"; +import type { Context, ContextFeatures } from "../../types"; import type { SubscriptionConnectionContext, SubscriptionContext } from "./subscriptions/types"; import type { Neo4jGraphQLSchemaModel } from "../../schema-model/Neo4jGraphQLSchemaModel"; import Cypher from "@neo4j/cypher-builder"; @@ -43,7 +43,6 @@ export type WrapResolverArguments = { relationships: Relationship[]; jwtPayloadFieldsMap?: Map; schemaModel: Neo4jGraphQLSchemaModel; - plugins?: Neo4jGraphQLPlugins; dbInfo?: Neo4jDatabaseInfo; features: ContextFeatures; authorization?: Neo4jGraphQLAuthorization; @@ -59,7 +58,6 @@ export const wrapResolver = relationships, jwtPayloadFieldsMap, schemaModel, - plugins, dbInfo, authorization, features, @@ -93,7 +91,6 @@ export const wrapResolver = context.nodes = nodes; context.relationships = relationships; context.schemaModel = schemaModel; - context.plugins = plugins || {}; context.subscriptionsEnabled = Boolean(features.subscriptions); context.callbacks = callbacks; context.features = features; @@ -140,7 +137,7 @@ export const wrapResolver = executorConstructorParam.cypherQueryOptions = context.cypherQueryOptions || config.cypherQueryOptions; - executorConstructorParam.sessionConfig = context.sessionConfig + executorConstructorParam.sessionConfig = context.sessionConfig; context.executor = new Executor(executorConstructorParam); diff --git a/packages/graphql/src/types/index.ts b/packages/graphql/src/types/index.ts index a5b49114df..19f4ab884c 100644 --- a/packages/graphql/src/types/index.ts +++ b/packages/graphql/src/types/index.ts @@ -50,7 +50,6 @@ export interface Context extends Neo4jGraphQLContext { schemaModel: Neo4jGraphQLSchemaModel; schema: GraphQLSchema; callbacks?: Neo4jGraphQLCallbacks; - plugins?: Neo4jGraphQLPlugins; features: ContextFeatures; subscriptionsEnabled: boolean; executor: Executor; @@ -318,20 +317,6 @@ export type StartupValidationConfig = StartupValidationOptions | boolean; /** Input field for graphql-compose */ export type InputField = { type: string; defaultValue?: string; directives?: Directive[] } | string; -export interface Neo4jGraphQLAuthPlugin { - rolesPath?: string; - isGlobalAuthenticationEnabled?: boolean; - bindPredicate?: "all" | "any"; - - decode(token: string): Promise; - /** - * This function tries to resolve public or secret keys. - * The implementation on how to resolve the keys by the `JWKSEndpoint` or by the `Secret` is set on when the plugin is being initiated. - * @param req - */ - tryToResolveKeys(req: unknown): void; -} - /** Raw event metadata returned from queries */ export type NodeSubscriptionMeta = { event: "create" | "update" | "delete"; @@ -444,10 +429,6 @@ export interface Neo4jGraphQLSubscriptionsMechanism { init?(): Promise; } -export interface Neo4jGraphQLPlugins { - auth?: Neo4jGraphQLAuthPlugin; -} - export type CallbackReturnValue = string | number | boolean | undefined | null; export type Neo4jGraphQLCallback = ( diff --git a/packages/graphql/tests/integration/subscriptions/single-instance-plugin.int.test.ts b/packages/graphql/tests/integration/subscriptions/single-instance-plugin.int.test.ts index 26264330e8..f6e61a137c 100644 --- a/packages/graphql/tests/integration/subscriptions/single-instance-plugin.int.test.ts +++ b/packages/graphql/tests/integration/subscriptions/single-instance-plugin.int.test.ts @@ -21,10 +21,10 @@ import { gql } from "graphql-tag"; import { graphql } from "graphql"; import type { Driver } from "neo4j-driver"; import { Neo4jGraphQL } from "../../../src"; -import type { EventMeta } from "../../../src"; import { Neo4jGraphQLSubscriptionsDefaultMechanism } from "../../../src/classes/Neo4jGraphQLSubscriptionsDefaultMechanism"; import { UniqueType } from "../../utils/graphql-types"; import Neo4j from "../neo4j"; +import type { EventMeta } from "../../../src/types"; describe("Subscriptions Single Instance Plugin", () => { let driver: Driver; diff --git a/packages/ogm/src/classes/OGM.ts b/packages/ogm/src/classes/OGM.ts index b40a72d35b..b6f7b3dfef 100644 --- a/packages/ogm/src/classes/OGM.ts +++ b/packages/ogm/src/classes/OGM.ts @@ -21,7 +21,7 @@ import type { Neo4jGraphQLConstructor, Node } from "@neo4j/graphql"; import { Neo4jGraphQL } from "@neo4j/graphql"; import type { GraphQLSchema } from "graphql"; import Model from "./Model"; -import { filterDocument } from "../utils"; +import { filterDocument } from "../utils/filter-document"; import type { Driver, SessionConfig } from "neo4j-driver"; export interface OGMConstructor extends Neo4jGraphQLConstructor { diff --git a/packages/ogm/src/generate.ts b/packages/ogm/src/generate.ts index 01f5928795..a21493b3e3 100644 --- a/packages/ogm/src/generate.ts +++ b/packages/ogm/src/generate.ts @@ -24,7 +24,6 @@ import * as fs from "fs"; import * as graphql from "graphql"; import prettier from "prettier"; import type { OGM } from "./index"; -import { getReferenceNode } from "./utils"; import { upperFirst } from "./utils/upper-first"; export interface IGenerateOptions { @@ -123,7 +122,7 @@ function createAggregationInput({ function hasConnectOrCreate(node: any, ogm: OGM): boolean { for (const relation of node.relationFields) { - const refNode = getReferenceNode(ogm, relation); + const refNode = ogm.nodes.find((x) => x.name === relation.typeMeta.name); if (refNode && refNode.uniqueFields.length > 0) { return true; } diff --git a/packages/ogm/src/utils/filter-document.test.ts b/packages/ogm/src/utils/filter-document.test.ts index 11bc8a6482..8851006a3d 100644 --- a/packages/ogm/src/utils/filter-document.test.ts +++ b/packages/ogm/src/utils/filter-document.test.ts @@ -18,7 +18,7 @@ */ import { print } from "graphql"; -import filterDocument from "./filter-document"; +import { filterDocument } from "./filter-document"; describe("filterDocument", () => { test("should remove all directives", () => { diff --git a/packages/ogm/src/utils/filter-document.ts b/packages/ogm/src/utils/filter-document.ts index 875872ab53..eaae4907b1 100644 --- a/packages/ogm/src/utils/filter-document.ts +++ b/packages/ogm/src/utils/filter-document.ts @@ -17,12 +17,7 @@ * limitations under the License. */ -import { - Kind, - type DefinitionNode, - type DocumentNode, - type FieldDefinitionNode, -} from "graphql"; +import { Kind, type DefinitionNode, type DocumentNode, type FieldDefinitionNode } from "graphql"; import type { Neo4jGraphQLConstructor } from "@neo4j/graphql"; import { mergeTypeDefs } from "@graphql-tools/merge"; @@ -43,7 +38,7 @@ const excludedDirectives = [ "settable", ]; -function filterDocument(typeDefs: Neo4jGraphQLConstructor["typeDefs"]): DocumentNode { +export function filterDocument(typeDefs: Neo4jGraphQLConstructor["typeDefs"]): DocumentNode { // hack to keep aggregation enabled for OGM const schemaExtension = ` extend schema @query(read: true, aggregate: true) @@ -90,9 +85,11 @@ function filterDocument(typeDefs: Neo4jGraphQLConstructor["typeDefs"]): Document ?.filter((x) => !excludedDirectives.includes(x.name.value)) .map((x) => { if (x.name.value === "relationship") { - const args = (x.arguments ? x.arguments?.filter( - (arg) => arg.name.value !== "aggregate" - ) : []) as any[]; // cast to any as this type is changing between GraphQL versions + const args = ( + x.arguments + ? x.arguments?.filter((arg) => arg.name.value !== "aggregate") + : [] + ) as any[]; // cast to any as this type is changing between GraphQL versions args?.push(relationshipAggregateArgument); return { ...x, @@ -110,5 +107,3 @@ function filterDocument(typeDefs: Neo4jGraphQLConstructor["typeDefs"]): Document }, []), }; } - -export default filterDocument; diff --git a/packages/ogm/src/utils/index.ts b/packages/ogm/src/utils/index.ts deleted file mode 100644 index 01b3a87de6..0000000000 --- a/packages/ogm/src/utils/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 type { Node, RelationField } from "@neo4j/graphql"; -import type { OGM } from ".."; - -export { default as filterDocument } from "./filter-document"; - -export function getReferenceNode(ogm: OGM, relationField: RelationField): Node | undefined { - return ogm.nodes.find((x) => x.name === relationField.typeMeta.name); -}