Skip to content

Commit

Permalink
Merge pull request #226 from oskarhane/fix-driver-datetime-issue
Browse files Browse the repository at this point in the history
Fix temporal type issues with [email protected]
  • Loading branch information
oskarhane authored May 28, 2021
2 parents dda2561 + b8c82e0 commit 1591800
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
6 changes: 3 additions & 3 deletions packages/graphql/src/schema/scalars/DateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
*/

import { GraphQLScalarType } from "graphql";
import { DateTime as Neo4jDateTime } from "neo4j-driver/lib/temporal-types";
import neo4j from "neo4j-driver";

export default new GraphQLScalarType({
name: "DateTime",
description: "A date and time, represented as an ISO-8601 string",
serialize: (value: Neo4jDateTime) => {
serialize: (value: typeof neo4j.types.DateTime) => {
return new Date(value.toString()).toISOString();
},
parseValue: (value: string) => {
return Neo4jDateTime.fromStandardDate(new Date(value));
return neo4j.types.DateTime.fromStandardDate(new Date(value));
},
});
20 changes: 14 additions & 6 deletions packages/graphql/tests/integration/types/datetime.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*/

import camelCase from "camelcase";
import { Driver } from "neo4j-driver";
import { DateTime } from "neo4j-driver/lib/temporal-types";
import neo4jDriver, { Driver } from "neo4j-driver";
import { graphql } from "graphql";
import { generate } from "randomstring";
import pluralize from "pluralize";
Expand Down Expand Up @@ -82,7 +81,10 @@ describe("DateTime", () => {
RETURN m {.id, .datetime} as m
`);

const movie: { id: string; datetime: DateTime } = (result.records[0].toObject() as any).m;
const movie: {
id: string;
datetime: typeof neo4jDriver.types.DateTime;
} = (result.records[0].toObject() as any).m;

expect(movie.id).toEqual(id);
expect(new Date(movie.datetime.toString()).toISOString()).toEqual(date.toISOString());
Expand Down Expand Up @@ -135,7 +137,10 @@ describe("DateTime", () => {
RETURN m {.id, .datetimes} as m
`);

const movie: { id: string; datetimes: DateTime[] } = (result.records[0].toObject() as any).m;
const movie: {
id: string;
datetimes: typeof neo4jDriver.types.DateTime[];
} = (result.records[0].toObject() as any).m;

expect(movie.id).toEqual(id);

Expand Down Expand Up @@ -178,7 +183,7 @@ describe("DateTime", () => {
}
`;

const nDateTime = DateTime.fromStandardDate(date);
const nDateTime = neo4jDriver.types.DateTime.fromStandardDate(date);

try {
await session.run(
Expand Down Expand Up @@ -303,7 +308,10 @@ describe("DateTime", () => {
RETURN m {.id, .datetime} as m
`);

const movie: { id: string; datetime: DateTime } = (result.records[0].toObject() as any).m;
const movie: {
id: string;
datetime: typeof neo4jDriver.types.DateTime;
} = (result.records[0].toObject() as any).m;

expect(movie.id).toEqual(id);
expect(new Date(movie.datetime.toString()).toISOString()).toEqual(date.toISOString());
Expand Down

0 comments on commit 1591800

Please sign in to comment.