Skip to content
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
6 changes: 6 additions & 0 deletions .changeset/sour-pugs-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@neo4j/graphql": major
"@neo4j/graphql-ogm": major
---

Remove all arguments from IExecutableSchemaDefinition apart from `typeDefs` and `resolvers`. This is to simplify the API and to remove any unexpected behaviours from arguments which we blindly pass through.
9 changes: 7 additions & 2 deletions docs/modules/ROOT/pages/guides/v4-migration/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Simply update `@neo4j/graphql` using npm or your package manager of choice:
npm update @neo4j/graphql
----

== Constructor arguments

If you were passing any arguments from https://the-guild.dev/graphql/tools/docs/api/interfaces/schema_src.iexecutableschemadefinition[`IExecutableSchemaDefinition`] into the library
other than `typeDefs` and `resolvers`, these are no longer supported.

== Updated Directives

We have renamed a number of directives and their arguments, in order to make using `@neo4j/graphql` more intuitive.
Expand All @@ -31,7 +36,7 @@ Therefore, the following usage of the directive would be invalid:
----
type User {
id: ID! @callback(name: "nanoid", operations: [CREATE])
firstName: String!
firstName: String!
surname: String!
}
----
Expand All @@ -42,7 +47,7 @@ It would instead need to be updated to use the new directive and argument as bel
----
type User {
id: ID! @populatedBy(callback: "nanoid", operations: [CREATE])
firstName: String!
firstName: String!
surname: String!
}
----
Expand Down
23 changes: 14 additions & 9 deletions packages/graphql/src/classes/Neo4jGraphQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { GraphQLSchema } from "graphql";
import type { IExecutableSchemaDefinition } from "@graphql-tools/schema";
import { makeExecutableSchema } from "@graphql-tools/schema";
import { composeResolvers } from "@graphql-tools/resolvers-composition";
import type { IResolvers } from "@graphql-tools/utils";
import type { IResolvers, TypeSource } from "@graphql-tools/utils";
import { forEachField } from "@graphql-tools/utils";
import { mergeResolvers } from "@graphql-tools/merge";
import Debug from "debug";
Expand Down Expand Up @@ -58,18 +58,22 @@ export interface Neo4jGraphQLConfig {
callbacks?: Neo4jGraphQLCallbacks;
}

export interface Neo4jGraphQLConstructor extends IExecutableSchemaDefinition {
export interface Neo4jGraphQLConstructor {
typeDefs: TypeSource;
resolvers?: IExecutableSchemaDefinition["resolvers"];
features?: Neo4jFeaturesSettings;
config?: Neo4jGraphQLConfig;
driver?: Driver;
plugins?: Neo4jGraphQLPlugins;
}

class Neo4jGraphQL {
typeDefs: TypeSource;
resolvers?: IExecutableSchemaDefinition["resolvers"];

private config: Neo4jGraphQLConfig;
private driver?: Driver;
private features?: Neo4jFeaturesSettings;
private schemaDefinition: IExecutableSchemaDefinition;

private _nodes?: Node[];
private _relationships?: Relationship[];
Expand All @@ -82,13 +86,15 @@ class Neo4jGraphQL {
private dbInfo?: Neo4jDatabaseInfo;

constructor(input: Neo4jGraphQLConstructor) {
const { config = {}, driver, plugins, features, ...schemaDefinition } = input;
const { config = {}, driver, plugins, features, typeDefs, resolvers } = input;

this.driver = driver;
this.config = config;
this.plugins = plugins;
this.features = features;
this.schemaDefinition = schemaDefinition;

this.typeDefs = typeDefs;
this.resolvers = resolvers;

this.checkEnableDebug();
}
Expand Down Expand Up @@ -219,21 +225,21 @@ class Neo4jGraphQL {
};

// Merge generated and custom resolvers
const mergedResolvers = mergeResolvers([resolvers, ...asArray(this.schemaDefinition.resolvers)]);
const mergedResolvers = mergeResolvers([resolvers, ...asArray(this.resolvers)]);
return composeResolvers(mergedResolvers, resolversComposition);
}

private generateSchema(): Promise<GraphQLSchema> {
return new Promise((resolve) => {
const document = getDocument(this.schemaDefinition.typeDefs);
const document = getDocument(this.typeDefs);

const { nodes, relationships, typeDefs, resolvers } = makeAugmentedSchema(document, {
features: this.features,
enableRegex: this.config?.enableRegex,
skipValidateTypeDefs: this.config?.skipValidateTypeDefs,
generateSubscriptions: Boolean(this.plugins?.subscriptions),
callbacks: this.config.callbacks,
userCustomResolvers: this.schemaDefinition.resolvers,
userCustomResolvers: this.resolvers,
});

const schemaModel = generateModel(document);
Expand All @@ -247,7 +253,6 @@ class Neo4jGraphQL {
const wrappedResolvers = this.wrapResolvers(resolvers);

const schema = makeExecutableSchema({
...this.schemaDefinition,
typeDefs,
resolvers: wrappedResolvers,
});
Expand Down