ash-project / ash-project/ash_graphql

Make sort/filter types optional and/or customizable

Open
#55 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Elixir
Stars
97
Forks
101
Avg merge
12h 51m
Merged PRs (30d)
5

Description

**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

```elixir
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
```

Contributor guide

Open the contributing guide

Research direction

Start by tracing how ash_graphql generates sort and filter types for GraphQL list queries and how the resource's `graphql`/`queries` configuration is read. Compare the requested per-action disable and field-limiting options, then verify that generated types expose only the permitted fields and that disabling either type removes it from the query.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir, graphql
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.