Skip to content

Commit

Permalink
chore: fix CI failures (#118)
Browse files Browse the repository at this point in the history
* chore: regenerate formatter and cheatsheets for paginate_with

* chore: fix credo errors

Use pattern matching to remove an if level and invert the logic on the
if Credo was complaining about
  • Loading branch information
rbino committed Mar 22, 2024
1 parent 51004af commit 1c47c79
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
1 change: 1 addition & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ spark_locals_without_parens = [
metadata_names: 1,
metadata_types: 1,
modify_resolution: 1,
paginate_with: 1,
primary_key_delimiter: 1,
read_action: 1,
read_one: 2,
Expand Down
1 change: 1 addition & 0 deletions documentation/dsls/DSL:-AshGraphql.Resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ list :list_posts_paginated, :read, relay?: true
| Name | Type | Default | Docs |
|------|------|---------|------|
| [`relay?`](#graphql-queries-list-relay?){: #graphql-queries-list-relay? } | `boolean` | `false` | If true, the graphql queries/resolvers for this resource will be built to honor the relay specification. See [the relay guide](/documentation/topics/relay.html) for more. |
| [`paginate_with`](#graphql-queries-list-paginate_with){: #graphql-queries-list-paginate_with } | `:keyset \| :offset \| nil` | `:keyset` | Determine the pagination strategy to use, if multiple are available. If `nil`, no pagination is applied, otherwise the given strategy is used. |
| [`type_name`](#graphql-queries-list-type_name){: #graphql-queries-list-type_name } | `atom` | | Override the type name returned by this query. Must be set if the read action has `metadata` that is not hidden via the `show_metadata` key. |
| [`metadata_names`](#graphql-queries-list-metadata_names){: #graphql-queries-list-metadata_names } | `keyword` | `[]` | Name overrides for metadata fields on the read action. |
| [`metadata_types`](#graphql-queries-list-metadata_types){: #graphql-queries-list-metadata_types } | `keyword` | `[]` | Type overrides for metadata fields on the read action. |
Expand Down
50 changes: 25 additions & 25 deletions lib/resource/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1277,36 +1277,36 @@ defmodule AshGraphql.Resource do
nil
end

defp pagination_strategy(%{paginate_with: strategy}, action) do
if !action.pagination do
nil
else
strategies =
if !action.pagination.required? do
[nil]
else
[]
end
defp pagination_strategy(_query, %{pagination: pagination}) when pagination in [nil, false] do
nil
end

strategies =
if action.pagination.keyset? do
[:keyset | strategies]
else
strategies
end
defp pagination_strategy(%{paginate_with: strategy}, action) do
strategies =
if action.pagination.required? do
[]
else
[nil]
end

strategies =
if action.pagination.offset? do
[:offset | strategies]
else
strategies
end
strategies =
if action.pagination.keyset? do
[:keyset | strategies]
else
strategies
end

if strategy in strategies do
strategy
strategies =
if action.pagination.offset? do
[:offset | strategies]
else
Enum.at(strategies, 0)
strategies
end

if strategy in strategies do
strategy
else
Enum.at(strategies, 0)
end
end

Expand Down

0 comments on commit 1c47c79

Please sign in to comment.