Skip to content

Commit 6e37f2f

Browse files
authored
Merge branch '4.0.0' into chore/remove-nodes-and-relationships
2 parents fb1cbcc + aa11d52 commit 6e37f2f

File tree

6 files changed

+111
-12
lines changed

6 files changed

+111
-12
lines changed

.changeset/new-comics-retire.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@neo4j/graphql": major
3+
"@neo4j/graphql-ogm": major
4+
---
5+
6+
Programmatic toggling of debug logging is now done using the `debug` option of the constructor.

docs/modules/ROOT/pages/migration/v4-migration/index.adoc

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,3 +880,61 @@ await startStandaloneServer(server, {
880880
----
881881

882882
The `bookmarks` key has been removed because it is no longer needed with the bookmark manager of the newer driver.
883+
884+
=== Debug logging
885+
886+
The programmatic toggle for debug logging has been moved from `config.enableDebug` to simply `debug`.
887+
888+
An example of `enableDebug`:
889+
890+
[source, javascript, indent=0]
891+
----
892+
const { Neo4jGraphQL } = require("@neo4j/graphql");
893+
const neo4j = require("neo4j-driver");
894+
const { ApolloServer } = require("apollo-server");
895+
896+
const typeDefs = `
897+
type Movie {
898+
title: String!
899+
}
900+
`;
901+
902+
const driver = neo4j.driver(
903+
"bolt://localhost:7687",
904+
neo4j.auth.basic("neo4j", "password")
905+
);
906+
907+
const neoSchema = new Neo4jGraphQL({
908+
typeDefs,
909+
driver,
910+
config: {
911+
enableDebug: true,
912+
}
913+
});
914+
----
915+
916+
This now becomes:
917+
918+
[source, javascript, indent=0]
919+
----
920+
const { Neo4jGraphQL } = require("@neo4j/graphql");
921+
const neo4j = require("neo4j-driver");
922+
const { ApolloServer } = require("apollo-server");
923+
924+
const typeDefs = `
925+
type Movie {
926+
title: String!
927+
}
928+
`;
929+
930+
const driver = neo4j.driver(
931+
"bolt://localhost:7687",
932+
neo4j.auth.basic("neo4j", "password")
933+
);
934+
935+
const neoSchema = new Neo4jGraphQL({
936+
typeDefs,
937+
driver,
938+
debug: true,
939+
});
940+
----

docs/modules/ROOT/pages/troubleshooting.adoc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ This chapter contains common troubleshooting steps. Additionally, there is a sec
1010

1111
`@neo4j/graphql` uses the https://www.npmjs.com/package/debug[`debug`] library for debug-level logging. You can turn on all debug logging by setting the environment variable `DEBUG` to `@neo4j/graphql:*` when running. For example:
1212

13+
==== Command line
14+
1315
[source, bash, indent=0]
1416
----
1517
DEBUG=@neo4j/graphql:* node src/index.js
@@ -22,6 +24,34 @@ Alternatively, if you are debugging a particular functionality, you can specify
2224
3. `@neo4j/graphql:graphql` - Logs the GraphQL query and variables
2325
4. `@neo4j/graphql:execute` - Logs the Cypher and Cypher paramaters before execution, and summary of execution
2426

27+
==== Constructor
28+
29+
You can also enable all debug logging in the library by setting the `debug` argument to `true` in the constructor.
30+
31+
[source, javascript, indent=0]
32+
----
33+
const { Neo4jGraphQL } = require("@neo4j/graphql");
34+
const neo4j = require("neo4j-driver");
35+
const { ApolloServer } = require("apollo-server");
36+
37+
const typeDefs = `
38+
type Movie {
39+
title: String!
40+
}
41+
`;
42+
43+
const driver = neo4j.driver(
44+
"bolt://localhost:7687",
45+
neo4j.auth.basic("neo4j", "password")
46+
);
47+
48+
const neoSchema = new Neo4jGraphQL({
49+
typeDefs,
50+
driver,
51+
debug: true,
52+
});
53+
----
54+
2555
=== For `@neo4j/introspector`
2656

2757
`@neo4j/introspector` has its own debug logging namespace and you can turn on logging for it with:

packages/graphql-toolbox/src/modules/EditorView/EditorView.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import { graphql } from "graphql";
2727

2828
import { tracking } from "../../analytics/tracking";
2929
import { Extension } from "../../components/Filename";
30-
import { EDITOR_PARAMS_INPUT, EDITOR_RESPONSE_OUTPUT } from "../../constants";
30+
import { DEFAULT_DATABASE_NAME, EDITOR_PARAMS_INPUT, EDITOR_RESPONSE_OUTPUT } from "../../constants";
31+
import { AuthContext } from "../../contexts/auth";
3132
import { Screen } from "../../contexts/screen";
3233
import { SettingsContext } from "../../contexts/settings";
3334
import { useStore } from "../../store";
@@ -47,6 +48,7 @@ export interface Props {
4748

4849
export const EditorView = ({ schema }: Props) => {
4950
const store = useStore();
51+
const auth = useContext(AuthContext);
5052
const settings = useContext(SettingsContext);
5153
const [loading, setLoading] = useState<boolean>(false);
5254
const [showDocs, setShowDocs] = useState<boolean>(false);
@@ -68,7 +70,11 @@ export const EditorView = ({ schema }: Props) => {
6870
const response = await graphql({
6971
schema: schema,
7072
source: override || useStore.getState().getActiveTab().query || "",
71-
contextValue: {},
73+
contextValue: {
74+
sessionConfig: {
75+
database: auth.selectedDatabaseName || DEFAULT_DATABASE_NAME,
76+
},
77+
},
7278
variableValues: safeParse(useStore.getState().getActiveTab().variables, {}),
7379
});
7480

packages/graphql-toolbox/src/modules/SchemaView/SchemaView.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,7 @@ export const SchemaView = ({ onSchemaChange }: Props) => {
122122
typeDefs,
123123
driver: auth.driver,
124124
features,
125-
config: {
126-
enableDebug: useStore.getState().enableDebug,
127-
sessionConfig: {
128-
database: auth.selectedDatabaseName || DEFAULT_DATABASE_NAME,
129-
},
130-
},
125+
debug: useStore.getState().enableDebug,
131126
};
132127

133128
const neoSchema = new Neo4jGraphQL(options);

packages/graphql/src/classes/Neo4jGraphQL.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import { Neo4jGraphQLAuthorization } from "./authorization/Neo4jGraphQLAuthoriza
5757
import { Neo4jGraphQLSubscriptionsDefaultMechanism } from "./Neo4jGraphQLSubscriptionsDefaultMechanism";
5858

5959
export interface Neo4jGraphQLConfig {
60-
enableDebug?: boolean;
6160
startupValidation?: StartupValidationConfig;
6261
cypherQueryOptions?: CypherQueryOptions;
6362
}
@@ -74,6 +73,7 @@ export interface Neo4jGraphQLConstructor {
7473
features?: Neo4jFeaturesSettings;
7574
config?: Neo4jGraphQLConfig;
7675
driver?: Driver;
76+
debug?: boolean;
7777
}
7878

7979
export const defaultValidationConfig: ValidationConfig = {
@@ -107,8 +107,10 @@ class Neo4jGraphQL {
107107

108108
private authorization?: Neo4jGraphQLAuthorization;
109109

110+
private debug?: boolean;
111+
110112
constructor(input: Neo4jGraphQLConstructor) {
111-
const { config = {}, driver, features, typeDefs, resolvers } = input;
113+
const { config = {}, driver, features, typeDefs, resolvers, debug } = input;
112114

113115
this.driver = driver;
114116
this.config = config;
@@ -117,6 +119,8 @@ class Neo4jGraphQL {
117119
this.typeDefs = typeDefs;
118120
this.resolvers = resolvers;
119121

122+
this.debug = debug;
123+
120124
this.checkEnableDebug();
121125

122126
if (this.features?.authorization) {
@@ -271,8 +275,8 @@ class Neo4jGraphQL {
271275
}
272276

273277
private checkEnableDebug(): void {
274-
if (this.config.enableDebug === true || this.config.enableDebug === false) {
275-
if (this.config.enableDebug) {
278+
if (this.debug === true || this.debug === false) {
279+
if (this.debug) {
276280
Debug.enable(DEBUG_ALL);
277281
} else {
278282
Debug.disable();

0 commit comments

Comments
 (0)