Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access async action id inside of action #8903

Open
adas98012 opened this issue Sep 1, 2022 Discussed in #8750 · 1 comment
Open

Access async action id inside of action #8903

adas98012 opened this issue Sep 1, 2022 Discussed in #8750 · 1 comment
Labels
a/api/graphql k/enhancement New feature or improve an existing feature t/gql-services

Comments

@adas98012
Copy link
Contributor

Discussed in #8750

Originally posted by talgat-ruby August 5, 2022
Hi

For example, lets say I have async action someAsyncAction. I can access action_id in the client via graphql.

mutation SomeAsyncActionRequest($name: String!) {
  someAsyncAction(name: $name)
}
{
  "data": {
    "someAsyncAction": "23b1c256-7aff-4b95-95bd-68220d9f93f2"
  }
}

But this is client. How about within action code? I want to save the action_id ro db to show its status only for a particular user.

module.exports = async (req, res) => {
  const { input, action } = req.body // can access action description: name, but why not id?
  const { name } = input

  try {
    const resp = await heavyRequest(name)

    res.send({
      success: resp.data.success
    })
  } catch (err) {
    res.status(400).json({
      message: err.message
    })
  }
}

The only workaround I found is to Proxy asynchronous action with synchronous action. Isn't it overhead.

@adas98012 adas98012 added k/enhancement New feature or improve an existing feature a/api/graphql labels Sep 1, 2022
@rakeshkky
Copy link
Member

The shape of action payload looks like the following (without any transformation)

{
  "action": {
    "name": "<action-name>"
  },
  "input": {
    "arg1": "<value>",
    "arg2": "<value>"
  },
  "session_variables": {
    "x-hasura-user-id": "<session-user-id>",
    "x-hasura-role": "<session-user-role>"
  },
  "request_query": "<request-query>"
}

We need to add action_id field to the payload, inside action object.

{
  "action": {
    "name": "<action-name>",
    "action_id": "<async-action-uuid>"
  },
  "input": {
    "arg1": "<value>",
    "arg2": "<value>"
  },
  "session_variables": {
    "x-hasura-user-id": "<session-user-id>",
    "x-hasura-role": "<session-user-role>"
  },
  "request_query": "<request-query>"
}

The action_id will be an optional value. It will be null for sync actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a/api/graphql k/enhancement New feature or improve an existing feature t/gql-services
Projects
None yet
Development

No branches or pull requests

3 participants