Skip to content

Commit

Permalink
Add point and time generic filters translation
Browse files Browse the repository at this point in the history
  • Loading branch information
angrykoala committed Nov 28, 2024
1 parent d20bf92 commit 74afc1c
Show file tree
Hide file tree
Showing 21 changed files with 1,950 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,14 @@ export class FilterFactory {
});
}

if (rawOperator === "distance") {
const distanceFilters = Object.entries(value).flatMap((distanceWhere) => {
return this.parseGenericFilter(entity, fieldName, distanceWhere);
});

return this.wrapMultipleFiltersInLogical(distanceFilters);
}

const operator = this.parseGenericOperator(rawOperator);

const attribute = entity.findAttribute(fieldName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { UniqueType } from "../../utils/graphql-types";
import { TestHelper } from "../../utils/tests-helper";

describe("[CartesianPoint] - deprecated filters", () => {
const testHelper = new TestHelper();
let Part: UniqueType;

beforeEach(async () => {
Part = testHelper.createUniqueType("Part");
const typeDefs = /* GraphQL */ `
type ${Part} @node {
id: String!
locations: [CartesianPoint!]!
}
`;
await testHelper.initNeo4jGraphQL({ typeDefs });
});

afterEach(async () => {
await testHelper.close();
});

test("enables query of a node with multiple cartesian points", async () => {
const id = "5ba92bc4-95e7-4361-857c-60edcd771391";
const locations = [...new Array(8)].map(() => ({
x: 0.02772025833837688,
y: 0.07264417805708945,
}));

await testHelper.executeCypher(
`
CALL {
CREATE (r:${Part})
SET r.id = $id
SET r.locations = [p in $locations | point(p)]
RETURN r
}
RETURN r { .id, .locations } AS r
`,
{ id, locations }
);

const partsQuery = /* GraphQL */ `
query Parts($id: String!) {
${Part.plural}(where: { id_EQ: $id }) {
id
locations {
y
x
z
crs
}
}
}
`;

const gqlResult = await testHelper.executeGraphQL(partsQuery, { variableValues: { id } });

expect(gqlResult.errors).toBeFalsy();
expect((gqlResult.data as any)[Part.plural][0]).toEqual({
id,
locations: locations.map((location) => ({ ...location, z: null, crs: "cartesian" })),
});
});

test("enables query of a node with multiple cartesian-3d points", async () => {
const id = "052322ec-95e5-4b88-8a90-9f0c1df17ee3";
const locations = [...new Array(8)].map(() => ({
x: 0.8367510938551277,
y: 0.7110547178890556,
z: 0.9648887133225799,
}));

await testHelper.executeCypher(
`
CALL {
CREATE (r:${Part})
SET r.id = $id
SET r.locations = [p in $locations | point(p)]
RETURN r
}
RETURN r { .id, .locations } AS r
`,
{ id, locations }
);

const partsQuery = /* GraphQL */ `
query Parts($id: String!) {
${Part.plural}(where: { id_EQ: $id }) {
id
locations {
y
x
z
crs
}
}
}
`;

const gqlResult = await testHelper.executeGraphQL(partsQuery, { variableValues: { id } });

expect(gqlResult.errors).toBeFalsy();
expect((gqlResult.data as any)[Part.plural][0]).toEqual({
id,
locations: locations.map((location) => ({ ...location, crs: "cartesian-3d" })),
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { UniqueType } from "../../utils/graphql-types";
import { TestHelper } from "../../utils/tests-helper";

describe("[Point] - deprecated filter", () => {
const testHelper = new TestHelper();
let Route: UniqueType;

beforeEach(async () => {
Route = testHelper.createUniqueType("Route");
const typeDefs = /* GraphQL */ `
type ${Route} @node {
id: String!
waypoints: [Point!]!
}
`;
await testHelper.initNeo4jGraphQL({ typeDefs });
});

afterEach(async () => {
await testHelper.close();
});

test("enables query of a node with multiple wgs-84 points", async () => {
// Create test data and prepare for testing
const id = "25c4676e-1e38-4b1b-b156-6a7e28c8013e";
const waypoints = [...new Array(9)].map(() => ({
longitude: parseFloat("34.1879"),
latitude: parseFloat("30.5402"),
}));

await testHelper.executeCypher(
`
CALL {
CREATE (r:${Route})
SET r.id = $id
SET r.waypoints = [p in $waypoints | point(p)]
RETURN r
}
RETURN r { .id, .waypoints } AS r
`,
{ id, waypoints }
);

// Test for equality
const routesQuery = /* GraphQL */ `
query Routes($waypoints: [PointInput!]) {
${Route.plural}(where: { waypoints_EQ: $waypoints }) {
id
waypoints {
latitude
longitude
height
crs
}
}
}
`;

const routesResult = await testHelper.executeGraphQL(routesQuery, { variableValues: { waypoints } });

expect(routesResult.errors).toBeFalsy();
expect((routesResult.data as any)[Route.plural][0]).toEqual({
id,
waypoints: waypoints.map((waypoint) => ({ ...waypoint, height: null, crs: "wgs-84" })),
});

// Test INCLUDES functionality
const routesIncludesQuery = /* GraphQL */ `
query RoutesIncludes($waypoint: PointInput) {
${Route.plural}(where: { waypoints_INCLUDES: $waypoint }) {
id
waypoints {
latitude
longitude
height
crs
}
}
}
`;

const routesIncludesResult = await testHelper.executeGraphQL(routesIncludesQuery, {
variableValues: { waypoint: waypoints[0] },
});

expect(routesIncludesResult.errors).toBeFalsy();
expect((routesIncludesResult.data as any)[Route.plural][0]).toEqual({
id,
waypoints: waypoints.map((waypoint) => ({ ...waypoint, height: null, crs: "wgs-84" })),
});
});

test("enables query of a node with multiple wgs-84-3d points", async () => {
const id = "dd320626-cc23-4938-9f33-ba624a3a3e8d";
const waypoints = [...new Array(7)].map(() => ({
longitude: parseFloat("146.1568"),
latitude: parseFloat("-54.6132"),
height: 0.03157347836531699,
}));

await testHelper.executeCypher(
`
CALL {
CREATE (r:${Route})
SET r.id = $id
SET r.waypoints = [p in $waypoints | point(p)]
RETURN r
}
RETURN r { .id, .waypoints } AS r
`,
{ id, waypoints }
);

const routesQuery = /* GraphQL */ `
query Routes($id: String!) {
${Route.plural}(where: { id_EQ: $id }) {
id
waypoints {
latitude
longitude
height
crs
}
}
}
`;

const gqlResult = await testHelper.executeGraphQL(routesQuery, {
variableValues: { id },
});

expect(gqlResult.errors).toBeFalsy();
expect((gqlResult.data as any)[Route.plural][0]).toEqual({
id,
waypoints: waypoints.map((waypoint) => ({ ...waypoint, crs: "wgs-84-3d" })),
});
});
});
Loading

0 comments on commit 74afc1c

Please sign in to comment.