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/witty-rabbits-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@neo4j/graphql": major
"@neo4j/graphql-ogm": major
---

`cypherQueryOptions` moved into context-only, as a per-request option.
17 changes: 11 additions & 6 deletions docs/modules/ROOT/pages/migration/v4-migration/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ type Actor @query(aggregate: true) {

If you had a need to pass in Cypher query options for query tuning, this interface has been changed.

The config option `queryOptions` has now become `cypherQueryOptions`, and it now accepts simple strings instead of enums.
The config option `queryOptions` has now become `cypherQueryOptions` inside the context function, and it now accepts simple strings instead of enums.

The following is an example before the change:

Expand Down Expand Up @@ -822,14 +822,19 @@ const typeDefs = `

const neoSchema = new Neo4jGraphQL({
typeDefs,
config: {
cypherQueryOptions: {
runtime: "interpreted",
},
},
});

const server = new ApolloServer({
schema: await neoSchema.getSchema(),
});

await startStandaloneServer(server, {
context: async ({ req }) => ({ cypherQueryOptions: { runtime: "interpreted" }}),
});
----

This reflects the fact that the Cypher query options are set on a per-request basis.

=== Session configuration

Session configuration is now available only in the context under the `sessionConfig` key.
Expand Down
45 changes: 2 additions & 43 deletions docs/modules/ROOT/pages/troubleshooting.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -66,54 +66,13 @@ Read more about the xref::introspector.adoc[introspector].
[[troubleshooting-query-tuning]]
== Query Tuning

Hopefully you won't need to perform any query tuning, but if you do, the Neo4j GraphQL Library allows you to set the full array of query options on construction of the library.
Hopefully you won't need to perform any query tuning, but if you do, the Neo4j GraphQL Library allows you to set the full array of query options in the request context.

You can read more about the available query options at https://neo4j.com/docs/cypher-manual/current/query-tuning/query-options/#cypher-query-options[Cypher Manual -> Query Options].

_Please only set these options if you know what you are doing._

For example, in order to set the Cypher runtime to "interpreted":

[source, javascript, indent=0]
----
const { Neo4jGraphQL } = require("@neo4j/graphql");
const neo4j = require("neo4j-driver");
const { ApolloServer } = require("apollo-server");

const typeDefs = `
type Movie {
title: String!
}
`;

const driver = neo4j.driver(
"bolt://localhost:7687",
neo4j.auth.basic("neo4j", "password")
);

const neoSchema = new Neo4jGraphQL({
typeDefs,
driver,
config: {
cypherQueryOptions: {
runtime: "interpreted",
},
},
});

neoSchema.getSchema().then((schema) => {
const server = new ApolloServer({
schema,
context: ({ req }) => ({ req }),
});

server.listen().then(({ url }) => {
console.log(`Server ready at ${url}`);
});
});
----

These options can also be set in the context function, which will take precedence:
For example, to set the "runtime" option to "interpreted":

[source, javascript, indent=0]
----
Expand Down
2 changes: 0 additions & 2 deletions packages/graphql/src/classes/Neo4jGraphQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
import Debug from "debug";
import type {
CypherQueryOptions,
Neo4jFeaturesSettings,
StartupValidationConfig,
ContextFeatures,
Expand Down Expand Up @@ -58,7 +57,6 @@ import { Neo4jGraphQLSubscriptionsDefaultMechanism } from "./Neo4jGraphQLSubscri

export interface Neo4jGraphQLConfig {
startupValidation?: StartupValidationConfig;
cypherQueryOptions?: CypherQueryOptions;
}

export type ValidationConfig = {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/schema/resolvers/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const wrapResolver =
executionContext: context.executionContext,
};

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

executorConstructorParam.sessionConfig = context.sessionConfig;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ describe("query options", () => {
const neoSchema = new Neo4jGraphQL({
typeDefs,
driver,
config: { cypherQueryOptions: { runtime: "interpreted" } },
});

const id = generate({
Expand Down Expand Up @@ -84,7 +83,7 @@ describe("query options", () => {
schema: await neoSchema.getSchema(),
source: query,
variableValues: { id },
contextValue: neo4j.getContextValues(),
contextValue: neo4j.getContextValues({ cypherQueryOptions: { runtime: "interpreted" } }),
});

expect(result.errors).toBeFalsy();
Expand Down