diff --git a/CHANGELOG.md b/CHANGELOG.md index c08c15be..c337681f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - server: add support for `_inc` on `real`, `double`, `numeric` and `money` (fix #3573) - server: support special characters in JSON path query argument with bracket `[]` notation, e.g `obj['Hello World!']` (#3890) (#4482) +- server: add graphql-engine support for timestamps without timezones (fix #1217) - console: change react ace editor theme to eclipse (close #4437) - console: fix columns reordering for relationship tables in data browser (#4483) - docs: add API docs for using environment variables as webhook urls in event triggers diff --git a/server/src-lib/Hasura/SQL/Types.hs b/server/src-lib/Hasura/SQL/Types.hs index 54795137..c2e612e5 100644 --- a/server/src-lib/Hasura/SQL/Types.hs +++ b/server/src-lib/Hasura/SQL/Types.hs @@ -342,6 +342,7 @@ data PGScalarType | PGText | PGCitext | PGDate + | PGTimeStamp | PGTimeStampTZ | PGTimeTZ | PGJSON @@ -373,6 +374,7 @@ instance ToSQL PGScalarType where PGText -> "text" PGCitext -> "citext" PGDate -> "date" + PGTimeStamp -> "timestamp" PGTimeStampTZ -> "timestamptz" PGTimeTZ -> "timetz" PGJSON -> "json" @@ -430,6 +432,9 @@ textToPGScalarType t = case t of "date" -> PGDate + "timestamp" -> PGTimeStamp + "timestamp without time zone" -> PGTimeStamp + "timestamptz" -> PGTimeStampTZ "timestamp with time zone" -> PGTimeStampTZ @@ -467,6 +472,7 @@ pgTypeOid PGVarchar = PTI.varchar pgTypeOid PGText = PTI.text pgTypeOid PGCitext = PTI.text -- Explict type cast to citext needed, See also Note [Type casting prepared params] pgTypeOid PGDate = PTI.date +pgTypeOid PGTimeStamp = PTI.timestamp pgTypeOid PGTimeStampTZ = PTI.timestamptz pgTypeOid PGTimeTZ = PTI.timetz pgTypeOid PGJSON = PTI.json diff --git a/server/src-lib/Hasura/SQL/Value.hs b/server/src-lib/Hasura/SQL/Value.hs index c3c427aa..c9ef5a1c 100644 --- a/server/src-lib/Hasura/SQL/Value.hs +++ b/server/src-lib/Hasura/SQL/Value.hs @@ -71,6 +71,7 @@ data PGScalarValue | PGValText !T.Text | PGValCitext !T.Text | PGValDate !Day + | PGValTimeStamp !LocalTime | PGValTimeStampTZ !UTCTime | PGValTimeTZ !ZonedTimeOfDay | PGNull !PGScalarType @@ -97,6 +98,8 @@ pgScalarValueToJson = \case PGValText t -> toJSON t PGValCitext t -> toJSON t PGValDate d -> toJSON d + PGValTimeStamp u -> + toJSON $ formatTime defaultTimeLocale "%FT%T%QZ" u PGValTimeStampTZ u -> toJSON $ formatTime defaultTimeLocale "%FT%T%QZ" u PGValTimeTZ (ZonedTimeOfDay tod tz) -> @@ -145,6 +148,7 @@ parsePGValue ty val = case (ty, val) of PGText -> PGValText <$> parseJSON val PGCitext -> PGValCitext <$> parseJSON val PGDate -> PGValDate <$> parseJSON val + PGTimeStamp -> PGValTimeStamp <$> parseJSON val PGTimeStampTZ -> PGValTimeStampTZ <$> parseJSON val PGTimeTZ -> PGValTimeTZ <$> parseJSON val PGJSON -> PGValJSON . Q.JSON <$> parseJSON val @@ -188,6 +192,8 @@ txtEncodedPGVal colVal = case colVal of PGValText t -> TELit t PGValCitext t -> TELit t PGValDate d -> TELit $ T.pack $ showGregorian d + PGValTimeStamp u -> + TELit $ T.pack $ formatTime defaultTimeLocale "%FT%T%QZ" u PGValTimeStampTZ u -> TELit $ T.pack $ formatTime defaultTimeLocale "%FT%T%QZ" u PGValTimeTZ (ZonedTimeOfDay tod tz) -> @@ -219,6 +225,7 @@ binEncoder colVal = case colVal of PGValText t -> Q.toPrepVal t PGValCitext t -> Q.toPrepVal t PGValDate d -> Q.toPrepVal d + PGValTimeStamp u -> Q.toPrepVal u PGValTimeStampTZ u -> Q.toPrepVal u PGValTimeTZ (ZonedTimeOfDay t z) -> Q.toPrepValHelper PTI.timetz PE.timetz_int (t, z) PGNull ty -> (pgTypeOid ty, Nothing) diff --git a/server/tests-py/queries/graphql_query/aggregations/article_agg_where.yaml b/server/tests-py/queries/graphql_query/aggregations/article_agg_where.yaml index 139048ac..896e4a1b 100644 --- a/server/tests-py/queries/graphql_query/aggregations/article_agg_where.yaml +++ b/server/tests-py/queries/graphql_query/aggregations/article_agg_where.yaml @@ -97,6 +97,8 @@ response: content_max: Sample article content 3 author_id: 2 author_id_max: 2 + published_on: '1999-01-09T04:05:06' + published_on_max: '1999-01-09T04:05:06' max_fields: id: 3 id_max: 3 @@ -106,6 +108,8 @@ response: content_max: Sample article content 3 author_id: 2 author_id_max: 2 + published_on: '1999-01-09T04:05:06' + published_on_max: '1999-01-09T04:05:06' min: id: 2 id_min: 2 @@ -115,6 +119,8 @@ response: content_min: Sample article content 2 author_id: 1 author_id_min: 1 + published_on: '1999-01-08T04:05:07' + published_on_min: '1999-01-08T04:05:07' min_fields: id: 2 id_min: 2 @@ -124,11 +130,14 @@ response: content_min: Sample article content 2 author_id: 1 author_id_min: 1 + published_on: '1999-01-08T04:05:07' + published_on_min: '1999-01-08T04:05:07' nodes: - id: 2 title: Article 2 content: Sample article content 2 is_published: true + published_on: '1999-01-08T04:05:07' author: id: 1 name: Author 1 @@ -136,6 +145,7 @@ response: title: Article 3 content: Sample article content 3 is_published: true + published_on: '1999-01-09T04:05:06' author: id: 2 name: Author 2 @@ -144,6 +154,7 @@ response: title: Article 2 content: Sample article content 2 is_published: true + published_on: '1999-01-08T04:05:07' author: id: 1 name: Author 1 @@ -151,6 +162,7 @@ response: title: Article 3 content: Sample article content 3 is_published: true + published_on: '1999-01-09T04:05:06' author: id: 2 name: Author 2 @@ -268,6 +280,8 @@ query: content_max: content author_id author_id_max: author_id + published_on + published_on_max: published_on } max_fields: max { id @@ -278,6 +292,8 @@ query: content_max: content author_id author_id_max: author_id + published_on + published_on_max: published_on } min { id @@ -288,6 +304,8 @@ query: content_min: content author_id author_id_min: author_id + published_on + published_on_min: published_on } min_fields: min { id @@ -298,6 +316,8 @@ query: content_min: content author_id author_id_min: author_id + published_on + published_on_min: published_on } } nodes { @@ -305,6 +325,7 @@ query: title content is_published + published_on author { id name @@ -315,6 +336,7 @@ query: title content is_published + published_on author { id name diff --git a/server/tests-py/queries/graphql_query/aggregations/setup.yaml b/server/tests-py/queries/graphql_query/aggregations/setup.yaml index f2f3e2ee..a11e2207 100644 --- a/server/tests-py/queries/graphql_query/aggregations/setup.yaml +++ b/server/tests-py/queries/graphql_query/aggregations/setup.yaml @@ -6,7 +6,7 @@ args: args: sql: | create table author( - id serial primary key, + id serial primary key, name text unique ); - type: track_table @@ -57,28 +57,31 @@ args: insert into author (name) values ('Author 1'), - ('Author 2') + ('Author 2') - type: run_sql args: sql: | - insert into article (title,content,author_id,is_published) + insert into article (title,content,author_id,is_published,published_on) values ( 'Article 1', 'Sample article content 1', 1, - false + false, + '1999-01-08 04:05:06' ), ( 'Article 2', 'Sample article content 2', 1, - true + true, + '1999-01-08 04:05:07' ), ( 'Article 3', 'Sample article content 3', 2, - true + true, + '1999-01-09 04:05:06' )