Skip to content

Commit 132f69b

Browse files
authored
Fix Notification.description polyfill from GqlStatusObject (#1205)
Bolt 5.6 introduces the original notification description back in the protocol level. This avoids the `Notification.description` changes when connected to GQL aware servers. This issues was detected during homologation, so the problem won't happen with any released server since the bolt version which miss information will not be released.
1 parent 4e8867c commit 132f69b

22 files changed

+1881
-25
lines changed

packages/bolt-connection/src/bolt/bolt-protocol-v5x5.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export default class BoltProtocol extends BoltProtocolV5x4 {
147147
afterComplete,
148148
highRecordWatermark,
149149
lowRecordWatermark,
150-
enrichMetadata: BoltProtocol._enrichMetadata
150+
enrichMetadata: this._enrichMetadata
151151
})
152152

153153
const flushRun = reactive
@@ -176,10 +176,11 @@ export default class BoltProtocol extends BoltProtocolV5x4 {
176176
* @param {object} metadata
177177
* @returns {object}
178178
*/
179-
static _enrichMetadata (metadata) {
179+
_enrichMetadata (metadata) {
180180
if (Array.isArray(metadata.statuses)) {
181181
metadata.statuses = metadata.statuses.map(status => ({
182182
...status,
183+
description: status.neo4j_code != null ? status.status_description : status.description,
183184
diagnostic_record: status.diagnostic_record !== null ? { ...DEFAULT_DIAGNOSTIC_RECORD, ...status.diagnostic_record } : null
184185
}))
185186
}

packages/bolt-connection/src/bolt/bolt-protocol-v5x5.transformer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18-
import v5x3 from './bolt-protocol-v5x3.transformer'
18+
import v5x4 from './bolt-protocol-v5x4.transformer'
1919

2020
export default {
21-
...v5x3
21+
...v5x4
2222
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [https://neo4j.com]
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
import BoltProtocolV5x5 from './bolt-protocol-v5x5'
18+
19+
import transformersFactories from './bolt-protocol-v5x5.transformer'
20+
import Transformer from './transformer'
21+
22+
import { internal } from 'neo4j-driver-core'
23+
24+
const {
25+
constants: { BOLT_PROTOCOL_V5_6 }
26+
} = internal
27+
28+
const DEFAULT_DIAGNOSTIC_RECORD = Object.freeze({
29+
OPERATION: '',
30+
OPERATION_CODE: '0',
31+
CURRENT_SCHEMA: '/'
32+
})
33+
34+
export default class BoltProtocol extends BoltProtocolV5x5 {
35+
get version () {
36+
return BOLT_PROTOCOL_V5_6
37+
}
38+
39+
get transformer () {
40+
if (this._transformer === undefined) {
41+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
42+
}
43+
return this._transformer
44+
}
45+
46+
/**
47+
*
48+
* @param {object} metadata
49+
* @returns {object}
50+
*/
51+
_enrichMetadata (metadata) {
52+
if (Array.isArray(metadata.statuses)) {
53+
metadata.statuses = metadata.statuses.map(status => ({
54+
...status,
55+
diagnostic_record: status.diagnostic_record !== null ? { ...DEFAULT_DIAGNOSTIC_RECORD, ...status.diagnostic_record } : null
56+
}))
57+
}
58+
59+
return metadata
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [https://neo4j.com]
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import v5x5 from './bolt-protocol-v5x5.transformer'
19+
20+
export default {
21+
...v5x5
22+
}

packages/bolt-connection/src/bolt/create.js

+9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import BoltProtocolV5x2 from './bolt-protocol-v5x2'
3030
import BoltProtocolV5x3 from './bolt-protocol-v5x3'
3131
import BoltProtocolV5x4 from './bolt-protocol-v5x4'
3232
import BoltProtocolV5x5 from './bolt-protocol-v5x5'
33+
import BoltProtocolV5x6 from './bolt-protocol-v5x6'
3334
// eslint-disable-next-line no-unused-vars
3435
import { Chunker, Dechunker } from '../channel'
3536
import ResponseHandler from './response-handler'
@@ -238,6 +239,14 @@ function createProtocol (
238239
log,
239240
onProtocolError,
240241
serversideRouting)
242+
case 5.6:
243+
return new BoltProtocolV5x6(server,
244+
chunker,
245+
packingConfig,
246+
createResponseHandler,
247+
log,
248+
onProtocolError,
249+
serversideRouting)
241250
default:
242251
throw newError('Unknown Bolt protocol version: ' + version)
243252
}

packages/bolt-connection/src/bolt/handshake.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function parseNegotiatedResponse (buffer, log) {
7676
*/
7777
function newHandshakeBuffer () {
7878
return createHandshakeMessage([
79-
[version(5, 5), version(5, 0)],
79+
[version(5, 6), version(5, 0)],
8080
[version(4, 4), version(4, 2)],
8181
version(4, 1),
8282
version(3, 0)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`#unit BoltProtocolV5x6 .packable() should resultant function not pack graph types (Node) 1`] = `"It is not allowed to pass nodes in query parameters, given: (c:a {a:"b"})"`;
4+
5+
exports[`#unit BoltProtocolV5x6 .packable() should resultant function not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`;
6+
7+
exports[`#unit BoltProtocolV5x6 .packable() should resultant function not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:"c"}]->(f)"`;
8+
9+
exports[`#unit BoltProtocolV5x6 .packable() should resultant function not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:"c"}]->"`;
10+
11+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`;
12+
13+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`;
14+
15+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`;
16+
17+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`;
18+
19+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`;
20+
21+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`;
22+
23+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`;
24+
25+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`;
26+
27+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`;
28+
29+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`;
30+
31+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`;
32+
33+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`;
34+
35+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Node with less fields) 1`] = `"Wrong struct size for Node, expected 4 but was 3"`;
36+
37+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Node with more fields) 1`] = `"Wrong struct size for Node, expected 4 but was 5"`;
38+
39+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`;
40+
41+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`;
42+
43+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`;
44+
45+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`;
46+
47+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`;
48+
49+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`;
50+
51+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 8 but was 5"`;
52+
53+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 8 but was 9"`;
54+
55+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`;
56+
57+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`;
58+
59+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 4 but was 3"`;
60+
61+
exports[`#unit BoltProtocolV5x6 .unpack() should not unpack with wrong size (UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 4 but was 5"`;

packages/bolt-connection/test/bolt/bolt-protocol-v5x5.test.js

+33-5
Original file line numberDiff line numberDiff line change
@@ -1176,18 +1176,20 @@ describe('#unit BoltProtocolV5x5', () => {
11761176
mode: WRITE
11771177
})
11781178

1179-
expect(observer._enrichMetadata).toBe(BoltProtocolV5x5._enrichMetadata)
1179+
expect(observer._enrichMetadata).toBe(protocol._enrichMetadata)
11801180
})
11811181

11821182
describe('BoltProtocolV5x5._enrichMetadata', () => {
1183+
const protocol = newProtocol()
1184+
11831185
it('should handle empty metadata', () => {
1184-
const metadata = BoltProtocolV5x5._enrichMetadata({})
1186+
const metadata = protocol._enrichMetadata({})
11851187

11861188
expect(metadata).toEqual({})
11871189
})
11881190

11891191
it('should handle metadata with random objects', () => {
1190-
const metadata = BoltProtocolV5x5._enrichMetadata({
1192+
const metadata = protocol._enrichMetadata({
11911193
a: 1133,
11921194
b: 345
11931195
})
@@ -1199,7 +1201,7 @@ describe('#unit BoltProtocolV5x5', () => {
11991201
})
12001202

12011203
it('should handle metadata not change notifications ', () => {
1202-
const metadata = BoltProtocolV5x5._enrichMetadata({
1204+
const metadata = protocol._enrichMetadata({
12031205
a: 1133,
12041206
b: 345,
12051207
notifications: [
@@ -1466,9 +1468,35 @@ describe('#unit BoltProtocolV5x5', () => {
14661468
_classification: undefined,
14671469
_position: undefined
14681470
})
1471+
],
1472+
[
1473+
[{
1474+
gql_status: '03N33',
1475+
status_description: 'info: description',
1476+
neo4j_code: 'Neo.Info.My.Code',
1477+
title: 'Mitt title',
1478+
diagnostic_record: {
1479+
_classification: 'SOME',
1480+
_severity: 'INFORMATION'
1481+
}
1482+
}],
1483+
[{
1484+
gql_status: '03N33',
1485+
status_description: 'info: description',
1486+
description: 'info: description',
1487+
neo4j_code: 'Neo.Info.My.Code',
1488+
title: 'Mitt title',
1489+
diagnostic_record: {
1490+
OPERATION: '',
1491+
OPERATION_CODE: '0',
1492+
CURRENT_SCHEMA: '/',
1493+
_classification: 'SOME',
1494+
_severity: 'INFORMATION'
1495+
}
1496+
}]
14691497
]
14701498
])('should handle statuses (%o) ', (statuses, expectedStatuses) => {
1471-
const metadata = BoltProtocolV5x5._enrichMetadata({
1499+
const metadata = protocol._enrichMetadata({
14721500
a: 1133,
14731501
b: 345,
14741502
statuses

0 commit comments

Comments
 (0)