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

Teach graphql integration to preload filters #895

Open
stephenh opened this issue Nov 24, 2023 · 0 comments
Open

Teach graphql integration to preload filters #895

stephenh opened this issue Nov 24, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@stephenh
Copy link
Collaborator

If a GraphQL query has super-obvious filters like:

query { books(filter: { title: "..." }) }

We could auto-map those to SQL WHERE clauses. The wrinkle is that usually there is a long-tail of filters that want to be "short-cuts" for the API, i.e. something like isPublisher=true maps to status => publisher or publisherId=2 maps to book.author.publisher.id=2.

We could potentially teach any entity to have a list of "out-of-the-box filters", which are basically rails scopes, like a map to:

  • Book.scopes
    • publisherId => ...expression that we can eval...
    • isPublisher => ...expression that we can eval...

Some of these scopes we should be able to create implicitly, i.e. from:

  • Primitives on the entity
  • Codegen-d relations on the entity
  • hasManyThrough / hasOneThroughs on the entity
  • Custom scopes (?) from like config.addScope? Would need to take an argument (the filter value(s)) and return a ParsedFindQuery-ish AST of how to execute it

It seems like filters would largely group into two buckets: within-entity & cross-entity. Within-entity filters can be evaluated using only the columns within the current table. Cross-entity filters need to do joins. This would have implications for relations maintaining the consistent worldview, b/c if a new entity is added to a filtered-down relation, we'd need to runtime eval the filter against the new entity.

Like if a GraphQL query was author(id:1) { books(filter: { status: published }) { title }, and we preload only ~10 of the authors 100 books, the a1.books collection is not actually fully loaded. And adding a new book may-or-may-not match the status = published filter.

I wonder if these filters are almost dynamic relations, i.e. should be seen as author -> books -> books(filter) that have their own dynamically-created relation, with its own loaded state. We have had difficulty doing things like author.books.load(...) --> ... in the past with the type system, so that doesn't bode well.

@stephenh stephenh added the enhancement New feature or request label Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant