Skip to content

Commit

Permalink
chore(server): tidy up the FromJSON Job instance
Browse files Browse the repository at this point in the history
PR-URL: hasura/graphql-engine-mono#8303
GitOrigin-RevId: bfdbb47ed1dd545df79f7e8604138d575489a0b9
  • Loading branch information
Tom Harding authored and hasura-bot committed Mar 14, 2023
1 parent b4157f5 commit a119260
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions server/src-lib/Hasura/Backends/BigQuery/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,24 +1126,20 @@ data Job = Job
deriving (Show)

instance FromJSON Job where
parseJSON =
J.withObject
"Job"
( \o -> do
kind <- o J..: "kind"
if kind == ("bigquery#job" :: Text)
then do
state <- do
status <- o J..: "status"
status J..: "state"
(jobId, location) <- do
ref <- o J..: "jobReference"
-- 'location' is needed in addition to 'jobId' to query a job's
-- status
(,) <$> ref J..: "jobId" <*> ref J..: "location"
pure Job {state, jobId, location}
else fail ("Invalid kind: " <> show kind)
)
parseJSON = J.withObject "Job" \o -> do
kind <- o J..: "kind"
if kind == ("bigquery#job" :: Text)
then do
state <- do
status <- o J..: "status"
status J..: "state"
(jobId, location) <- do
ref <- o J..: "jobReference"
-- 'location' is needed in addition to 'jobId' to query a job's
-- status
(,) <$> ref J..: "jobId" <*> ref J..: "location"
pure Job {state, jobId, location}
else fail ("Invalid kind: " <> show kind)

instance ToJSON Job where
toJSON Job {..} =
Expand Down

0 comments on commit a119260

Please sign in to comment.