Skip to content

Commit d4aea32

Browse files
authored
Assessment and grouping of all library exports (#3670)
* Assessment and grouping of all library exports * Add changeset * Fix test import * Fix doc blocks
1 parent 0e23ec5 commit d4aea32

File tree

11 files changed

+44
-88
lines changed

11 files changed

+44
-88
lines changed

.changeset/loud-rivers-wonder.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+
Removal of the following exports: `Neo4jGraphQLAuthenticationError`, `Neo4jGraphQLForbiddenError`, `EventMeta`, `Neo4jGraphQLAuthPlugin` and `RelationField`. This are either redundant, or internals which shouldn't have been exported.

packages/graphql/src/classes/Neo4jGraphQL.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
2121
import Debug from "debug";
2222
import type {
2323
CypherQueryOptions,
24-
Neo4jGraphQLPlugins,
2524
Neo4jFeaturesSettings,
2625
StartupValidationConfig,
2726
ContextFeatures,
@@ -75,7 +74,6 @@ export interface Neo4jGraphQLConstructor {
7574
features?: Neo4jFeaturesSettings;
7675
config?: Neo4jGraphQLConfig;
7776
driver?: Driver;
78-
plugins?: Neo4jGraphQLPlugins;
7977
}
8078

8179
export const defaultValidationConfig: ValidationConfig = {
@@ -94,7 +92,6 @@ class Neo4jGraphQL {
9492

9593
private _nodes?: Node[];
9694
private _relationships?: Relationship[];
97-
private plugins?: Neo4jGraphQLPlugins;
9895

9996
private jwtFieldsMap?: Map<string, string>;
10097

@@ -111,11 +108,10 @@ class Neo4jGraphQL {
111108
private authorization?: Neo4jGraphQLAuthorization;
112109

113110
constructor(input: Neo4jGraphQLConstructor) {
114-
const { config = {}, driver, plugins, features, typeDefs, resolvers } = input;
111+
const { config = {}, driver, features, typeDefs, resolvers } = input;
115112

116113
this.driver = driver;
117114
this.config = config;
118-
this.plugins = plugins;
119115
this.features = this.parseNeo4jFeatures(features);
120116

121117
this.typeDefs = typeDefs;
@@ -313,7 +309,6 @@ class Neo4jGraphQL {
313309
nodes: this.nodes,
314310
relationships: this.relationships,
315311
schemaModel: this.schemaModel,
316-
plugins: this.plugins,
317312
features: this.features,
318313
authorization: this.authorization,
319314
jwtPayloadFieldsMap: this.jwtFieldsMap,

packages/graphql/src/index.ts

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

20+
import { Neo4jGraphQL, Neo4jGraphQLConstructor } from "./classes";
21+
import { Neo4jGraphQLContext } from "./types/neo4j-graphql-context";
22+
2023
import { CartesianPoint } from "./graphql/objects/CartesianPoint";
2124
import { Point } from "./graphql/objects/Point";
25+
import * as directives from "./graphql/directives";
26+
import * as scalars from "./graphql/scalars";
27+
const objects = { Point, CartesianPoint };
2228

23-
export {
24-
Neo4jGraphQL,
25-
Neo4jGraphQLAuthenticationError,
26-
Neo4jGraphQLConstructor,
27-
Neo4jGraphQLForbiddenError,
28-
} from "./classes";
29-
export * as directives from "./graphql/directives";
30-
export * as scalars from "./graphql/scalars";
31-
export {
29+
import {
3230
DeleteInfo,
33-
EventMeta,
3431
GraphQLOptionsArg,
3532
GraphQLSortArg,
3633
GraphQLWhereArg,
37-
Neo4jGraphQLAuthPlugin,
3834
Neo4jGraphQLSubscriptionsMechanism,
3935
Node,
40-
RelationField,
4136
SubscriptionsEvent,
4237
} from "./types";
4338

44-
export { Neo4jGraphQLContext } from "./types/neo4j-graphql-context";
39+
/**
40+
* Core library functionality.
41+
*/
42+
export { Neo4jGraphQL, Neo4jGraphQLConstructor, Neo4jGraphQLContext };
43+
44+
/**
45+
* Library built-in GraphQL types.
46+
*/
47+
export { directives, scalars, objects };
4548

46-
export const objects = { Point, CartesianPoint };
49+
/**
50+
* Exports for usage by the OGM.
51+
*/
52+
export { DeleteInfo, GraphQLOptionsArg, GraphQLSortArg, GraphQLWhereArg, Node };
53+
54+
/**
55+
* Allows for the implementation of custom subscriptions mechanisms.
56+
*/
57+
export { Neo4jGraphQLSubscriptionsMechanism, SubscriptionsEvent };

packages/graphql/src/schema/resolvers/wrapper.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { getNeo4jDatabaseInfo } from "../../classes/Neo4jDatabaseInfo";
2828
import { Executor } from "../../classes/Executor";
2929
import type { ExecutorConstructorParam } from "../../classes/Executor";
3030
import { AUTH_FORBIDDEN_ERROR, DEBUG_GRAPHQL } from "../../constants";
31-
import type { Context, ContextFeatures, Neo4jGraphQLPlugins } from "../../types";
31+
import type { Context, ContextFeatures } from "../../types";
3232
import type { SubscriptionConnectionContext, SubscriptionContext } from "./subscriptions/types";
3333
import type { Neo4jGraphQLSchemaModel } from "../../schema-model/Neo4jGraphQLSchemaModel";
3434
import Cypher from "@neo4j/cypher-builder";
@@ -43,7 +43,6 @@ export type WrapResolverArguments = {
4343
relationships: Relationship[];
4444
jwtPayloadFieldsMap?: Map<string, string>;
4545
schemaModel: Neo4jGraphQLSchemaModel;
46-
plugins?: Neo4jGraphQLPlugins;
4746
dbInfo?: Neo4jDatabaseInfo;
4847
features: ContextFeatures;
4948
authorization?: Neo4jGraphQLAuthorization;
@@ -59,7 +58,6 @@ export const wrapResolver =
5958
relationships,
6059
jwtPayloadFieldsMap,
6160
schemaModel,
62-
plugins,
6361
dbInfo,
6462
authorization,
6563
features,
@@ -93,7 +91,6 @@ export const wrapResolver =
9391
context.nodes = nodes;
9492
context.relationships = relationships;
9593
context.schemaModel = schemaModel;
96-
context.plugins = plugins || {};
9794
context.subscriptionsEnabled = Boolean(features.subscriptions);
9895
context.callbacks = callbacks;
9996
context.features = features;
@@ -140,7 +137,7 @@ export const wrapResolver =
140137

141138
executorConstructorParam.cypherQueryOptions = context.cypherQueryOptions || config.cypherQueryOptions;
142139

143-
executorConstructorParam.sessionConfig = context.sessionConfig
140+
executorConstructorParam.sessionConfig = context.sessionConfig;
144141

145142
context.executor = new Executor(executorConstructorParam);
146143

packages/graphql/src/types/index.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export interface Context extends Neo4jGraphQLContext {
5050
schemaModel: Neo4jGraphQLSchemaModel;
5151
schema: GraphQLSchema;
5252
callbacks?: Neo4jGraphQLCallbacks;
53-
plugins?: Neo4jGraphQLPlugins;
5453
features: ContextFeatures;
5554
subscriptionsEnabled: boolean;
5655
executor: Executor;
@@ -318,20 +317,6 @@ export type StartupValidationConfig = StartupValidationOptions | boolean;
318317
/** Input field for graphql-compose */
319318
export type InputField = { type: string; defaultValue?: string; directives?: Directive[] } | string;
320319

321-
export interface Neo4jGraphQLAuthPlugin {
322-
rolesPath?: string;
323-
isGlobalAuthenticationEnabled?: boolean;
324-
bindPredicate?: "all" | "any";
325-
326-
decode<T>(token: string): Promise<T | undefined>;
327-
/**
328-
* This function tries to resolve public or secret keys.
329-
* The implementation on how to resolve the keys by the `JWKSEndpoint` or by the `Secret` is set on when the plugin is being initiated.
330-
* @param req
331-
*/
332-
tryToResolveKeys(req: unknown): void;
333-
}
334-
335320
/** Raw event metadata returned from queries */
336321
export type NodeSubscriptionMeta = {
337322
event: "create" | "update" | "delete";
@@ -444,10 +429,6 @@ export interface Neo4jGraphQLSubscriptionsMechanism {
444429
init?(): Promise<void>;
445430
}
446431

447-
export interface Neo4jGraphQLPlugins {
448-
auth?: Neo4jGraphQLAuthPlugin;
449-
}
450-
451432
export type CallbackReturnValue = string | number | boolean | undefined | null;
452433

453434
export type Neo4jGraphQLCallback = (

packages/graphql/tests/integration/subscriptions/single-instance-plugin.int.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import { gql } from "graphql-tag";
2121
import { graphql } from "graphql";
2222
import type { Driver } from "neo4j-driver";
2323
import { Neo4jGraphQL } from "../../../src";
24-
import type { EventMeta } from "../../../src";
2524
import { Neo4jGraphQLSubscriptionsDefaultMechanism } from "../../../src/classes/Neo4jGraphQLSubscriptionsDefaultMechanism";
2625
import { UniqueType } from "../../utils/graphql-types";
2726
import Neo4j from "../neo4j";
27+
import type { EventMeta } from "../../../src/types";
2828

2929
describe("Subscriptions Single Instance Plugin", () => {
3030
let driver: Driver;

packages/ogm/src/classes/OGM.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type { Neo4jGraphQLConstructor, Node } from "@neo4j/graphql";
2121
import { Neo4jGraphQL } from "@neo4j/graphql";
2222
import type { GraphQLSchema } from "graphql";
2323
import Model from "./Model";
24-
import { filterDocument } from "../utils";
24+
import { filterDocument } from "../utils/filter-document";
2525
import type { Driver, SessionConfig } from "neo4j-driver";
2626

2727
export interface OGMConstructor extends Neo4jGraphQLConstructor {

packages/ogm/src/generate.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import * as fs from "fs";
2424
import * as graphql from "graphql";
2525
import prettier from "prettier";
2626
import type { OGM } from "./index";
27-
import { getReferenceNode } from "./utils";
2827
import { upperFirst } from "./utils/upper-first";
2928

3029
export interface IGenerateOptions {
@@ -123,7 +122,7 @@ function createAggregationInput({
123122

124123
function hasConnectOrCreate(node: any, ogm: OGM): boolean {
125124
for (const relation of node.relationFields) {
126-
const refNode = getReferenceNode(ogm, relation);
125+
const refNode = ogm.nodes.find((x) => x.name === relation.typeMeta.name);
127126
if (refNode && refNode.uniqueFields.length > 0) {
128127
return true;
129128
}

packages/ogm/src/utils/filter-document.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
import { print } from "graphql";
21-
import filterDocument from "./filter-document";
21+
import { filterDocument } from "./filter-document";
2222

2323
describe("filterDocument", () => {
2424
test("should remove all directives", () => {

packages/ogm/src/utils/filter-document.ts

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

20-
import {
21-
Kind,
22-
type DefinitionNode,
23-
type DocumentNode,
24-
type FieldDefinitionNode,
25-
} from "graphql";
20+
import { Kind, type DefinitionNode, type DocumentNode, type FieldDefinitionNode } from "graphql";
2621
import type { Neo4jGraphQLConstructor } from "@neo4j/graphql";
2722
import { mergeTypeDefs } from "@graphql-tools/merge";
2823

@@ -43,7 +38,7 @@ const excludedDirectives = [
4338
"settable",
4439
];
4540

46-
function filterDocument(typeDefs: Neo4jGraphQLConstructor["typeDefs"]): DocumentNode {
41+
export function filterDocument(typeDefs: Neo4jGraphQLConstructor["typeDefs"]): DocumentNode {
4742
// hack to keep aggregation enabled for OGM
4843
const schemaExtension = `
4944
extend schema @query(read: true, aggregate: true)
@@ -90,9 +85,11 @@ function filterDocument(typeDefs: Neo4jGraphQLConstructor["typeDefs"]): Document
9085
?.filter((x) => !excludedDirectives.includes(x.name.value))
9186
.map((x) => {
9287
if (x.name.value === "relationship") {
93-
const args = (x.arguments ? x.arguments?.filter(
94-
(arg) => arg.name.value !== "aggregate"
95-
) : []) as any[]; // cast to any as this type is changing between GraphQL versions
88+
const args = (
89+
x.arguments
90+
? x.arguments?.filter((arg) => arg.name.value !== "aggregate")
91+
: []
92+
) as any[]; // cast to any as this type is changing between GraphQL versions
9693
args?.push(relationshipAggregateArgument);
9794
return {
9895
...x,
@@ -110,5 +107,3 @@ function filterDocument(typeDefs: Neo4jGraphQLConstructor["typeDefs"]): Document
110107
}, []),
111108
};
112109
}
113-
114-
export default filterDocument;

0 commit comments

Comments
 (0)