question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use session variables in GraphQL queries

See original GitHub issue

Hi all, it would be great to inject my X-Hasura-User-Id into my GraphQL query so I can use it to filter through data. E.g, fetching the tasks assigned to my currently authenticated user. Are there any plans to build this?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:55
  • Comments:20 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
macalinaocommented, Aug 23, 2019

@0x777 one idea is to inject all hasura env vars as optional query variables. I’m not sure what the security implications are, but it could look like this:

query getFollowersOf($x_hasura_user_id: String) {
  followers(where: {user_id: {_eq: $x_hasura_user_id}}) {
    follower_id
  }
}

These could get whitelisted and configured in the Hasura console

7reactions
0x777commented, Aug 21, 2019

@macalinao I’m not sure how this can be done while adhering to the graphql spec. Any ideas?

@victorferreira I think what the op was suggesting is a case like this: Suppose you have a table/view called followers where everyone can read all rows. Now suppose you want to fetch your own followers you would do something like this:

query getFollowersOf($user_id: Int!) {
  followers(where: {user_id: {_eq: $user_id}}) {
    follower_id
  }
}

with variables being {"user_id": your_user_id}. However it would be nice if you can somehow specify that $user_id should come from a session variable than having to explicitly specify it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Roles & Session variables | Hasura GraphQL Docs
Session variables are key-value pairs returned from the authentication service for ... Hasura allows you to create permission rules that can use any...
Read more >
set session variable for Hasura on Query in apollo client ...
I have got a query in apollo graphql, that I want to attach a variable to, in the header of the request. The...
Read more >
GraphQL variables in simple terms - LogRocket Blog
In GraphQL, you can use variables to reuse the same query/mutations written by the client, with different arguments.
Read more >
Executing Queries - GraphQL Ruby
GraphQL provides query variables as a way to parameterize query strings. If your query string contains variables, you can provide values in a...
Read more >
GraphQL: Onsite Sessions - Techdocs
When a new user comes to the app, you can use this method to get a new session. It will return you a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found