Skip to content

Commit

Permalink
improvement: add show_fields option as explicit fields whitelist (#120
Browse files Browse the repository at this point in the history
)
  • Loading branch information
vonagam authored Mar 27, 2024
1 parent 98baf6f commit 1f2358e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/resource/info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,17 @@ defmodule AshGraphql.Resource.Info do
Extension.get_opt(resource, [:graphql], :hide_fields, [])
end

@doc "Fields to show in the graphql api"
def show_fields(resource) do
Extension.get_opt(resource, [:graphql], :show_fields, nil)
end

@doc "Wether or not a given field will be shown"
def show_field?(resource, field) do
field not in hide_fields(resource)
hide_fields = hide_fields(resource)
show_fields = show_fields(resource) || [field]

field not in hide_fields and field in show_fields
end

@doc "Which relationships should be included in the generated type"
Expand Down
5 changes: 5 additions & 0 deletions lib/resource/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ defmodule AshGraphql.Resource do
type: {:list, :atom},
doc: "A list of attributes to hide from the api"
],
show_fields: [
type: {:list, :atom},
doc:
"A list of attributes to show in the api. If not specified includes all (excluding `hide_fiels`)."
],
argument_names: [
type: :keyword_list,
doc:
Expand Down

0 comments on commit 1f2358e

Please sign in to comment.