mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-20 22:11:45 +03:00
3a400fab3d
### Description This PR rewrites OpenAPI to be more idiomatic. Some noteworthy changes: - we accumulate all required information during the Analyze phase, to avoid having to do a single lookup in the schema cache during the OpenAPI generation phase (we now only need the schema cache as input to run the analysis) - we no longer build intermediary endpoint information and aggregate it, we directly build the the `PathItem` for each endpoint; additionally, that means we no longer have to assume that different methods have the same metadata - we no longer have to first declare types, then craft references: we do everything in one step - we now properly deal with nullability by treating "typeName" and "typeName!" as different - we add a bunch of additional fields in the generated "schema", such as title - we do now support enum values in both input and output positions - checking whether the request body is required is now performed on the fly rather than by introspecting the generated schema - the methods in the file are sorted by topic ### Controversial point However, this PR creates some additional complexity, that we might not want to keep. The main complexity is _knot-tying_: to avoid lookups when generating the OpenAPI, it builds an actual graph of input types, which means that we need something similar to (but simpler than) `MonadSchema`, to avoid infinite recursions when analyzing the input types of a query. To do this, this PR introduces `CircularT`, a lesser `SchemaT` that aims at avoiding ever having to reinvent this particular wheel ever again. ### Remaining work - [x] fix existing tests (they are all failing due to some of the schema changes) - [ ] add tests to cover the new features: - [x] tests for `CircularT` - [ ] tests for enums in output schemas - [x] extract / document `CircularT` if we wish to keep it - [x] add more comments to `OpenAPI` - [x] have a second look at `buildVariableSchema` - [x] fix all missing diagnostics in `Analyze` - [x] add a Changelog entry? PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4654 Co-authored-by: David Overton <7734777+dmoverton@users.noreply.github.com> GitOrigin-RevId: f4a9191f22dfcc1dccefd6a52f5c586b6ad17172
31 lines
831 B
Haskell
31 lines
831 B
Haskell
module Hasura.SQL.Time
|
|
( ZonedTimeOfDay (..),
|
|
)
|
|
where
|
|
|
|
import Data.Aeson.Types qualified as Aeson
|
|
import Data.Attoparsec.Text as A
|
|
import Data.Attoparsec.Time (timeOfDay, timeZone)
|
|
import Data.Time.LocalTime qualified as Local
|
|
import Hasura.Prelude
|
|
|
|
data ZonedTimeOfDay = ZonedTimeOfDay
|
|
{ ztodTime :: Local.TimeOfDay,
|
|
ztodZone :: Local.TimeZone
|
|
}
|
|
deriving (Show, Eq)
|
|
|
|
utc :: Local.TimeZone
|
|
utc = Local.TimeZone 0 False ""
|
|
|
|
zonedTimeOfDay :: Text -> Aeson.Parser ZonedTimeOfDay
|
|
zonedTimeOfDay t =
|
|
A.parseOnly (p <* endOfInput) t
|
|
`onLeft` \err -> fail $ "could not parse timetz: " ++ err
|
|
where
|
|
p = ZonedTimeOfDay <$> timeOfDay <*> (fromMaybe utc <$> timeZone)
|
|
|
|
instance Aeson.FromJSON ZonedTimeOfDay where
|
|
parseJSON (Aeson.String t) = zonedTimeOfDay t
|
|
parseJSON _ = fail "Expecting a string for timetz"
|