Skip to content

Fixes cypher 25 check for semver servers #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 22, 2025
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
3 changes: 1 addition & 2 deletions packages/language-support/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ export { lintCypherQuery } from './syntaxValidation/syntaxValidation';
export type { SyntaxDiagnostic } from './syntaxValidation/syntaxValidation';
export { testData } from './tests/testData';
export { textMateGrammar } from './textMateGrammar';
export { cypherVersions } from './types';
export { allCypherVersions } from './types';
export type {
CompletionItem,
CypherVersion,
Neo4jFunction,
Neo4jProcedure,
} from './types';
export { cypher25Supported } from './version';
export { CypherLexer, CypherParser, CypherParserListener, CypherParserVisitor };

import CypherLexer from './generated-parser/CypherCmdLexer';
Expand Down
8 changes: 6 additions & 2 deletions packages/language-support/src/parserWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ import {
} from './helpers';
import { SyntaxDiagnostic } from './syntaxValidation/syntaxValidation';
import { SyntaxErrorsListener } from './syntaxValidation/syntaxValidationHelpers';
import { CypherVersion, cypherVersionNumbers, cypherVersions } from './types';
import {
CypherVersion,
cypherVersionNumbers,
allCypherVersions,
} from './types';

export interface ParsedStatement {
command: ParsedCommand;
Expand Down Expand Up @@ -494,7 +498,7 @@ class CypherVersionCollector extends ParseTreeListener {
exitEveryRule(ctx: unknown) {
if (ctx instanceof CypherVersionContext) {
const parsedVersion = 'CYPHER ' + ctx.getText();
cypherVersions.forEach((validVersion) => {
allCypherVersions.forEach((validVersion) => {
if (parsedVersion === validVersion) {
this.cypherVersion = parsedVersion;
}
Expand Down
23 changes: 0 additions & 23 deletions packages/language-support/src/tests/version.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/language-support/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export type ReturnDescription = {
isDeprecated: boolean;
};

export const cypherVersions = ['CYPHER 5', 'CYPHER 25'];
export const allCypherVersions = ['CYPHER 5', 'CYPHER 25'];
export const cypherVersionNumbers: string[] = ['5', '25'];
export type CypherVersion = (typeof cypherVersions)[number];
export type CypherVersion = (typeof allCypherVersions)[number];

// we could parse this string for better types in the future
export type Neo4jStringType = string;
Expand Down
27 changes: 0 additions & 27 deletions packages/language-support/src/version.ts

This file was deleted.

10 changes: 4 additions & 6 deletions packages/query-tools/src/metadataPoller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { CypherVersion } from '@neo4j-cypher/language-support';
import {
_internalFeatureFlags,
cypher25Supported,
cypherVersions,
allCypherVersions,
DbSchema,
Neo4jFunction,
Neo4jProcedure,
Expand Down Expand Up @@ -115,14 +114,13 @@ export class ConnectedMetadataPoller extends MetadataPoller {
constructor(
databases: Database[],
parameters: Record<string, unknown>,
serverVersion: string | undefined,
serverCypherVersions: string[] | undefined,
private readonly connection: Neo4jConnection,
private readonly events: EventEmitter,
) {
super();
const supportsCypherAnnotation =
_internalFeatureFlags.cypher25 ||
(serverVersion && cypher25Supported(serverVersion));
_internalFeatureFlags.cypher25 || serverCypherVersions?.includes('25');

this.dbSchema.parameters = parameters;

Expand Down Expand Up @@ -183,7 +181,7 @@ export class ConnectedMetadataPoller extends MetadataPoller {
});

const versions: (CypherVersion | undefined)[] = supportsCypherAnnotation
? cypherVersions
? allCypherVersions
: [undefined];

versions.forEach((cypherVersion) => {
Expand Down
42 changes: 38 additions & 4 deletions packages/query-tools/src/queries/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,46 @@ export function getVersion(): ExecuteQueryArgs<{
const resultTransformer = resultTransformers.mappedResultTransformer({
map(record) {
const obj = record.toObject();
const name = obj.name as string;
const versions = obj.versions as string[];
const version = versions?.at(0);
return version;
return { name, versions };
},
collect(versions, summary) {
return { serverVersion: versions.at(0), summary };
collect(rows, summary) {
rows.forEach((row) => {
if (row.name === 'Neo4j Kernel') {
return { serverVersion: row.versions, summary };
}
});
//We should not reach this unless the "name" field changes
return { serverVersion: undefined, summary };
},
});

return {
query,
queryConfig: { resultTransformer, routing: 'READ', database: 'system' },
};
}

export function getCypherVersions(): ExecuteQueryArgs<{
serverCypherVersions: string[] | undefined;
}> {
const query = 'CALL dbms.components() YIELD name, versions';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

originally I wanted this query to end with : WHERE name = "Cypher" RETURN versions
but this fails on system db.

Instead I opted to sort out the "Cypher" row and "versions" column in the resulttransformer.


const resultTransformer = resultTransformers.mappedResultTransformer({
map(record) {
const obj = record.toObject();
const name = obj.name as string;
const versions = obj.versions as string[];
return { name, versions };
},
collect(rows, summary) {
rows.forEach((row) => {
if (row.name === 'Cypher') {
return { serverCypherVersions: row.versions, summary };
}
});
return { serverCypherVersions: ['5'], summary };
},
});

Expand Down
14 changes: 7 additions & 7 deletions packages/query-tools/src/schemaPoller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from './metadataPoller';
import { Neo4jConnection } from './neo4jConnection';
import { listDatabases } from './queries/databases.js';
import { getVersion } from './queries/version';
import { getCypherVersions } from './queries/version';

export type ConnnectionResult = {
success: boolean;
Expand Down Expand Up @@ -180,18 +180,18 @@ export class Neo4jSchemaPoller {
database,
);

const { query: versionQuery, queryConfig: versionQueryConfig } =
getVersion();
const { serverVersion } = await this.driver.executeQuery(
versionQuery,
const { query: cypherVersionQuery, queryConfig: cypherVersionQueryConfig } =
getCypherVersions();
const { serverCypherVersions } = await this.driver.executeQuery(
cypherVersionQuery,
{},
versionQueryConfig,
cypherVersionQueryConfig,
);

this.metadata = new ConnectedMetadataPoller(
databases,
this.parameters,
serverVersion,
serverCypherVersions,
this.connection,
this.events,
);
Expand Down