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

Make sort/filter types optional and/or customizable #55

Open
sezaru opened this issue Feb 8, 2023 · 3 comments
Open

Make sort/filter types optional and/or customizable #55

sezaru opened this issue Feb 8, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@sezaru
Copy link
Contributor

sezaru commented Feb 8, 2023

Is your feature request related to a problem? Please describe.
Sort/filter types are always added by default in a GraphQL query by ash_graphql, but sometimes you want to implement your own sort/filter mechanism to limit what the users can do in your database (ex. restricting them from create not well optimized queries).

Describe the solution you'd like
I think there is two solutions here, it would be great to have both if possible.

The first one is to simply give an option to disable sort or filter types for an specific action.

The second one is to allow the user to customize these types for a specific option, for example, the user can say that what are the fields that the sort type can expose as sortable. That way I have the best of both words, I can restrict what fields can be filtered or sorted but still use the ash_graphql types so that is generated automatically for me instead of having to create a custom solution..

Express the feature either with a change to resource syntax, or with a change to the resource interface

For example

graphql do
  type :property

  queries do
    list :list_property, :read do
      # Makes PropertySortField only contain 'updated_at', 'inserted_at' and 'id' fields
      sort_by [:updated_at, :inserted_at, :id]

      # Makes PropertyFilterInput only filter by 'price', 'name' and 'address' fields
      filter_by [:price, :name, :address]
    end
  end
end
@sezaru sezaru added the enhancement New feature or request label Feb 8, 2023
@zachdaniel
Copy link
Contributor

Hey there! In the short term we can make the filter/sortability optional, but making it customizable per query would be a bit harder. I'll push up a resource-level toggle to turn those off, and then you can handle them yourself with arguments :)

@zachdaniel
Copy link
Contributor

Alright, I've pushed up these options:

graphql do
  ...
  derive_filter? false
  derive_sort? false
end

@zachdaniel
Copy link
Contributor

Give main a shot and see how it goes :)

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

2 participants