Skip to content

Commit 64f518a

Browse files
committed
feat: include builtin predicate functions in GraphQL filter schema
1 parent 781e0ca commit 64f518a

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

lib/resource/resource.ex

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,8 +2626,12 @@ defmodule AshGraphql.Resource do
26262626
array_type? = match?({:array, _}, type)
26272627

26282628
fields =
2629-
Ash.Filter.builtin_operators()
2630-
|> Enum.concat(Ash.DataLayer.functions(resource))
2629+
[
2630+
Ash.Filter.builtin_operators(),
2631+
Ash.Filter.builtin_functions(),
2632+
Ash.DataLayer.functions(resource)
2633+
]
2634+
|> Enum.concat()
26312635
|> Enum.filter(& &1.predicate?())
26322636
|> restrict_for_lists(type)
26332637
|> restrict_for_field(resource, attribute_or_aggregate)
@@ -2920,8 +2924,12 @@ defmodule AshGraphql.Resource do
29202924
array_type? = match?({:array, _}, field_type)
29212925

29222926
filter_fields =
2923-
Ash.Filter.builtin_operators()
2924-
|> Enum.concat(Ash.DataLayer.functions(resource))
2927+
[
2928+
Ash.Filter.builtin_operators(),
2929+
Ash.Filter.builtin_functions(),
2930+
Ash.DataLayer.functions(resource)
2931+
]
2932+
|> Enum.concat()
29252933
|> Enum.filter(& &1.predicate?())
29262934
|> restrict_for_lists(field_type)
29272935
|> restrict_for_field(resource, calculation)
@@ -5027,8 +5035,8 @@ defmodule AshGraphql.Resource do
50275035
if Application.compile_env(:ash_graphql, :warn_on_json_fallback?, true) do
50285036
defp warn_on_json_fallback(resource, constraints) do
50295037
IO.warn("""
5030-
Struct type with instance_of constraint falls back to JsonString for input.
5031-
Consider creating a custom type with `use AshGraphql.Type` and `graphql_input_type/1`
5038+
Struct type with instance_of constraint falls back to JsonString for input.
5039+
Consider creating a custom type with `use AshGraphql.Type` and `graphql_input_type/1`
50325040
for structured validation.
50335041
50345042
Resource: #{inspect(resource)}

lib/resource/verifiers/verify_filterable_fields.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ defmodule AshGraphql.Resource.Verifiers.VerifyFilterableFields do
7878
resource = Transformer.get_persisted(dsl, :module)
7979

8080
builtin =
81-
Ash.Filter.builtin_operators()
81+
[Ash.Filter.builtin_operators(), Ash.Filter.builtin_functions()]
82+
|> Enum.concat()
8283
|> Enum.filter(& &1.predicate?())
8384
|> Enum.map(& &1.name())
8485

test/filter_sort_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ defmodule AshGraphql.FilterSortTest do
108108
assert "eq" in field_names
109109
assert "lessThan" in field_names
110110
assert "greaterThan" in field_names
111+
assert "contains" in field_names
111112
end
112113

113114
test "sortable_fields option is applied" do

0 commit comments

Comments
 (0)