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

Allow VOLATILE functions for queries and subscriptions #6333

Closed
ayuryshev opened this issue Dec 12, 2020 · 2 comments
Closed

Allow VOLATILE functions for queries and subscriptions #6333

ayuryshev opened this issue Dec 12, 2020 · 2 comments

Comments

@ayuryshev
Copy link

ayuryshev commented Dec 12, 2020

This issue is written in response for #1514 (comment)

Please don't reject this proposal outright from theorethical standpoint that queries must be without side effects.

There are 2 cross-cutting concerns that could be solved with impure functions:

  • server-side memoization
  • logging

Server-side memoization

Consider the following scenario:

  • there is a big historical table with millions of records
  • there is a need to provide aggregate data from this table
  • this aggregate data is rarely needed and it's not needed for everyday functionality of system
  • it costs a lot to prepare such aggregated data for all records

With impure function it could be implemented as:

  • look for prepared aggregate data
  • if not exists - prepare it
  • return prepared data

This way only first query will execute long time, next queries will be fast and aggregated data will be shared between users.

Such functions would work extremely well in case of subscriptions.

Logging

Sometimes arises a need to have log of queries.

E.g. right now I have a need to check that frontend application pass correct hasura session parameter into functions.

With impure functions it could be dumb simple: create log table, write function parameters into it.

Right now I don't have such option. I need to check it by other means.

Logging in query functions would be extremely well in development environments.

Overall

From theorethical standpoint both cases violates principle that graphlq queries must be "side-effect free".

From practical POV - I think that even Seymour Peyton-Jones will not object such "violations".

Please consider such functionality.

@karibertils
Copy link

These are definitely useful and practical things I would like having when working with Hasura.

@tirumaraiselvan
Copy link
Contributor

Thank you for the detailed description of the use-case. VOLATILE functions will be supported as queries as well (ref: #1514 (comment)).

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

No branches or pull requests

3 participants