这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@codingkarthik
Copy link
Contributor

@codingkarthik codingkarthik commented Apr 9, 2020

  • the extensions can take any json

fixes #4001

Description

Changelog

  • CHANGELOG.md is updated with user-facing content relevant to this PR.

Affected components

  • Server
  • Console
  • CLI
  • Docs
  • Community Content
  • Build System
  • Tests
  • Other (list it)

Related Issues

Solution and Design

Steps to test and verify

Limitations, known bugs & workarounds

Server checklist

Catalog upgrade

Does this PR change Hasura Catalog version?

  • No
  • Yes
    • Updated docs with SQL for downgrading the catalog

Metadata

Does this PR add a new Metadata feature?

  • No
  • Yes
    • Does run_sql auto manages the new metadata through schema diffing?
      • Yes
      • Not required
    • Does run_sql auto manages the definitions of metadata on renaming?
      • Yes
      • Not required
    • Does export_metadata/replace_metadata supports the new metadata added?
      • Yes
      • Not required

GraphQL

  • No new GraphQL schema is generated
  • New GraphQL schema is being generated:
    • New types and typenames are correlated

Breaking changes

  • No Breaking changes

  • There are breaking changes:

    1. Metadata API

      Existing query types:

      • Modify args payload which is not backward compatible
      • Behavioural change of the API
      • Change in response JSON schema
      • Change in error code
    2. GraphQL API

      Schema Generation:

      • Change in any NamedType
      • Change in table field names

      Schema Resolve:-

      • Change in treatment of null value for any input fields
    3. Logging

      • Log JSON schema has changed
      • Log type names have changed

@codingkarthik codingkarthik requested a review from a team as a code owner April 9, 2020 11:54
@hasura-bot
Copy link
Contributor

Review app for commit 3b85b73 deployed to Heroku: https://hge-ci-pull-4351.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4351-3b85b73a

@0x777 0x777 requested a review from rakeshkky April 9, 2020 12:11

| HTTP.statusIsClientError responseStatus -> do
ActionWebhookErrorResponse message maybeCode <-
ActionWebhookErrorResponse message maybeCode maybeExtension <-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not take code anymore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See spec: #4001 (comment)

It is find to do this "breaking" change because we introduced it in beta.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept code thinking about the breaking change, I'll fix this

Copy link
Contributor

@tirumaraiselvan tirumaraiselvan Apr 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codingkarthik Cool. Also, could you also update the docs with this PR itself? This section: https://hasura.io/docs/1.0/graphql/manual/actions/action-handlers.html#returning-an-error-response

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll make the changes

@codingkarthik codingkarthik requested review from a team as code owners April 9, 2020 12:48
@netlify
Copy link

netlify bot commented Apr 9, 2020

Deploy preview for hasura-docs ready!

Built with commit 6b5c579

https://deploy-preview-4351--hasura-docs.netlify.com

@hasura-bot
Copy link
Contributor

Review app for commit e6ffc0a deployed to Heroku: https://hge-ci-pull-4351.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4351-e6ffc0a6

= ActionWebhookErrorExtension
{ _aweeExtension :: !J.Value
}
$(J.deriveJSON (J.aesonDrop 5 J.snakeCase) ''ActionWebhookErrorExtension)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a new type which is just a wrapper over J.Value.

qErr = QErr [] responseStatus message code Nothing
let qErr = QErr [] responseStatus message Unexpected $
(maybe Nothing (Just . J.toJSON . ActionWebhookErrorExtension) maybeExtension)
throwError qErr
Copy link
Member

@rakeshkky rakeshkky Apr 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qeInternal of QErr will go into extensions -> internal of the response json. So the response look like

extensions:
  internal:
    extensions: response-json-from-webhook

See encodeGQLErr function.

I'd suggest to model the extensions in the QErr type.

+data ErrorExtra
+  = EEInternal !Value
+  | EEExtensions !Value
+  deriving (Show, Eq)
+
+instance ToJSON ErrorExtra where
+  toJSON = \case
+    EEInternal v -> v
+    EEExtensions v -> v
+
 data QErr
   = QErr
-  { qePath     :: !JSONPath
-  , qeStatus   :: !N.Status
-  , qeError    :: !T.Text
-  , qeCode     :: !Code
-  , qeInternal :: !(Maybe Value)
+  { qePath   :: !JSONPath
+  , qeStatus :: !N.Status
+  , qeError  :: !T.Text
+  , qeCode   :: !Code
+  , qeExtra  :: !(Maybe ErrorExtra)
   } deriving (Show, Eq)
 
 instance ToJSON QErr where
@@ -157,12 +167,12 @@ instance ToJSON QErr where
     , "error" .= msg
     , "code"  .= show code
     ]
-  toJSON (QErr jPath _ msg code (Just ie)) =
+  toJSON (QErr jPath _ msg code (Just extra)) =
     object
     [ "path"  .= encodeJSONPath jPath
     , "error" .= msg
     , "code"  .= show code
-    , "internal" .= ie
+    , "internal" .= extra
     ]
 
 noInternalQErrEnc :: QErr -> Value
@@ -174,18 +184,20 @@ noInternalQErrEnc (QErr jPath _ msg code _) =
   ]
 
 encodeGQLErr :: Bool -> QErr -> Value
-encodeGQLErr includeInternal (QErr jPath _ msg code mIE) =
+encodeGQLErr includeInternal (QErr jPath _ msg code mExtra) =
   object
   [ "message" .= msg
   , "extensions" .= extnsObj
   ]
   where
-    extnsObj = object $ bool codeAndPath
-               (codeAndPath ++ internal) includeInternal
+    extnsObj = case mExtra of
+      Nothing -> object codeAndPath
+      Just (EEExtensions v) -> v
+      Just (EEInternal v) -> object $
+        bool codeAndPath (codeAndPath ++ ["internal" .= v]) includeInternal
     codeAndPath = [ "code" .= show code
                   , "path" .= encodeJSONPath jPath
                   ]
-    internal = maybe [] (\ie -> ["internal" .= ie]) mIE

Copy link
Member

@rakeshkky rakeshkky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add python tests. Also try to document the new types the PR introduces. In this case, for the suggested ErrorExtra type,

data ErrorExtra
  = EEInternal !Value 
    -- ^ Additional information for the server internal errors. 
  | EEExtensions !Value 
    -- ^ Custom extensions json value found in actions webhook response. 
  deriving (Show, Eq)

Copy link
Contributor

@marionschleifer marionschleifer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changelog approved.

- ErrorExtra is used to give the errors context while deriving to JSON
@hasura-bot
Copy link
Contributor

Review app for commit f67eb3a deployed to Heroku: https://hge-ci-pull-4351.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4351-f67eb3ab

@hasura-bot
Copy link
Contributor

Review app for commit 37210c8 deployed to Heroku: https://hge-ci-pull-4351.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4351-37210c81

@hasura-bot
Copy link
Contributor

Review app for commit 6b5c579 deployed to Heroku: https://hge-ci-pull-4351.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4351-6b5c5798

@ecthiender
Copy link
Contributor

Superseded by 8bfcd9a

@ecthiender ecthiender closed this Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

actions: ability to send extensions to error responses

6 participants