Skip to content

Commit 34ddf0a

Browse files
authored
Fixes cypher 25 check for semver servers (#508)
1 parent d08dc15 commit 34ddf0a

File tree

8 files changed

+58
-73
lines changed

8 files changed

+58
-73
lines changed

packages/language-support/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ export { lintCypherQuery } from './syntaxValidation/syntaxValidation';
2424
export type { SyntaxDiagnostic } from './syntaxValidation/syntaxValidation';
2525
export { testData } from './tests/testData';
2626
export { textMateGrammar } from './textMateGrammar';
27-
export { cypherVersions } from './types';
27+
export { allCypherVersions } from './types';
2828
export type {
2929
CompletionItem,
3030
CypherVersion,
3131
Neo4jFunction,
3232
Neo4jProcedure,
3333
} from './types';
34-
export { cypher25Supported } from './version';
3534
export { CypherLexer, CypherParser, CypherParserListener, CypherParserVisitor };
3635

3736
import CypherLexer from './generated-parser/CypherCmdLexer';

packages/language-support/src/parserWrapper.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ import {
3131
} from './helpers';
3232
import { SyntaxDiagnostic } from './syntaxValidation/syntaxValidation';
3333
import { SyntaxErrorsListener } from './syntaxValidation/syntaxValidationHelpers';
34-
import { CypherVersion, cypherVersionNumbers, cypherVersions } from './types';
34+
import {
35+
CypherVersion,
36+
cypherVersionNumbers,
37+
allCypherVersions,
38+
} from './types';
3539

3640
export interface ParsedStatement {
3741
command: ParsedCommand;
@@ -494,7 +498,7 @@ class CypherVersionCollector extends ParseTreeListener {
494498
exitEveryRule(ctx: unknown) {
495499
if (ctx instanceof CypherVersionContext) {
496500
const parsedVersion = 'CYPHER ' + ctx.getText();
497-
cypherVersions.forEach((validVersion) => {
501+
allCypherVersions.forEach((validVersion) => {
498502
if (parsedVersion === validVersion) {
499503
this.cypherVersion = parsedVersion;
500504
}

packages/language-support/src/tests/version.test.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/language-support/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export type ReturnDescription = {
77
isDeprecated: boolean;
88
};
99

10-
export const cypherVersions = ['CYPHER 5', 'CYPHER 25'];
10+
export const allCypherVersions = ['CYPHER 5', 'CYPHER 25'];
1111
export const cypherVersionNumbers: string[] = ['5', '25'];
12-
export type CypherVersion = (typeof cypherVersions)[number];
12+
export type CypherVersion = (typeof allCypherVersions)[number];
1313

1414
// we could parse this string for better types in the future
1515
export type Neo4jStringType = string;

packages/language-support/src/version.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

packages/query-tools/src/metadataPoller.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import type { CypherVersion } from '@neo4j-cypher/language-support';
22
import {
33
_internalFeatureFlags,
4-
cypher25Supported,
5-
cypherVersions,
4+
allCypherVersions,
65
DbSchema,
76
Neo4jFunction,
87
Neo4jProcedure,
@@ -115,14 +114,13 @@ export class ConnectedMetadataPoller extends MetadataPoller {
115114
constructor(
116115
databases: Database[],
117116
parameters: Record<string, unknown>,
118-
serverVersion: string | undefined,
117+
serverCypherVersions: string[] | undefined,
119118
private readonly connection: Neo4jConnection,
120119
private readonly events: EventEmitter,
121120
) {
122121
super();
123122
const supportsCypherAnnotation =
124-
_internalFeatureFlags.cypher25 ||
125-
(serverVersion && cypher25Supported(serverVersion));
123+
_internalFeatureFlags.cypher25 || serverCypherVersions?.includes('25');
126124

127125
this.dbSchema.parameters = parameters;
128126

@@ -183,7 +181,7 @@ export class ConnectedMetadataPoller extends MetadataPoller {
183181
});
184182

185183
const versions: (CypherVersion | undefined)[] = supportsCypherAnnotation
186-
? cypherVersions
184+
? allCypherVersions
187185
: [undefined];
188186

189187
versions.forEach((cypherVersion) => {

packages/query-tools/src/queries/version.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,46 @@ export function getVersion(): ExecuteQueryArgs<{
1212
const resultTransformer = resultTransformers.mappedResultTransformer({
1313
map(record) {
1414
const obj = record.toObject();
15+
const name = obj.name as string;
1516
const versions = obj.versions as string[];
16-
const version = versions?.at(0);
17-
return version;
17+
return { name, versions };
1818
},
19-
collect(versions, summary) {
20-
return { serverVersion: versions.at(0), summary };
19+
collect(rows, summary) {
20+
rows.forEach((row) => {
21+
if (row.name === 'Neo4j Kernel') {
22+
return { serverVersion: row.versions, summary };
23+
}
24+
});
25+
//We should not reach this unless the "name" field changes
26+
return { serverVersion: undefined, summary };
27+
},
28+
});
29+
30+
return {
31+
query,
32+
queryConfig: { resultTransformer, routing: 'READ', database: 'system' },
33+
};
34+
}
35+
36+
export function getCypherVersions(): ExecuteQueryArgs<{
37+
serverCypherVersions: string[] | undefined;
38+
}> {
39+
const query = 'CALL dbms.components() YIELD name, versions';
40+
41+
const resultTransformer = resultTransformers.mappedResultTransformer({
42+
map(record) {
43+
const obj = record.toObject();
44+
const name = obj.name as string;
45+
const versions = obj.versions as string[];
46+
return { name, versions };
47+
},
48+
collect(rows, summary) {
49+
rows.forEach((row) => {
50+
if (row.name === 'Cypher') {
51+
return { serverCypherVersions: row.versions, summary };
52+
}
53+
});
54+
return { serverCypherVersions: ['5'], summary };
2155
},
2256
});
2357

packages/query-tools/src/schemaPoller.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from './metadataPoller';
1414
import { Neo4jConnection } from './neo4jConnection';
1515
import { listDatabases } from './queries/databases.js';
16-
import { getVersion } from './queries/version';
16+
import { getCypherVersions } from './queries/version';
1717

1818
export type ConnnectionResult = {
1919
success: boolean;
@@ -180,18 +180,18 @@ export class Neo4jSchemaPoller {
180180
database,
181181
);
182182

183-
const { query: versionQuery, queryConfig: versionQueryConfig } =
184-
getVersion();
185-
const { serverVersion } = await this.driver.executeQuery(
186-
versionQuery,
183+
const { query: cypherVersionQuery, queryConfig: cypherVersionQueryConfig } =
184+
getCypherVersions();
185+
const { serverCypherVersions } = await this.driver.executeQuery(
186+
cypherVersionQuery,
187187
{},
188-
versionQueryConfig,
188+
cypherVersionQueryConfig,
189189
);
190190

191191
this.metadata = new ConnectedMetadataPoller(
192192
databases,
193193
this.parameters,
194-
serverVersion,
194+
serverCypherVersions,
195195
this.connection,
196196
this.events,
197197
);

0 commit comments

Comments
 (0)