pierreabreup
Paginate root object with Absinthe
This is my schema:
defmodule ContentProxyGraphql.Schema.ObjectTypes.Content do
use Absinthe.Schema.Notation
import_types Absinthe.Type.Custom
import_types ContentProxyGraphql.Schema.ObjectTypes.{
Person,
Language,
Publisher
}
alias ContentProxyGraphql.Resolvers
object :content do
field :type_of, non_null(:string)
field :name, non_null(:string)
field :date_created, non_null(:datetime)
field :date_modified, non_null(:datetime)
field :learning_resource_type, non_null(:string)
field :description, :string
field :thumbnail_url, :string
field :license, :string
field :educational_use, :string
field :interactivity_type, :string
field :url, :string
field :author, list_of(:person)
field :additional_property, list_of(:property_value)
field :educational_alignment, list_of(:alignment_object)
field :identifier, non_null(:property_value)
field :publisher, :publisher
field :in_language, :language
field :audience, :education_audience
field :is_part_of, :content_reference
end
object :property_value do
field :type_of, non_null(:string)
field :property_id, non_null(:string)
field :value, non_null(:string)
end
object :education_audience do
field :type_of, non_null(:string)
field :education_role, non_null(:string)
end
object :alignment_object do
field :type_of, non_null(:string)
field :alignment_type, non_null(:string)
field :educational_framework, non_null(:string)
field :target_name, non_null(:string)
field :target_url, :string
end
object :content_reference do
field :type_of, non_null(:string)
field :identifier, :property_value
end
object :content_queries do
field :contents, list_of(:content) do
arg :type_of, :string
resolve &Resolvers.Resources.Content.list/2
end
end
end
When I doing a query, I get this result:
I’m struggling to implement absinthe pagination on root object (in my case :content) because all of absinthe examples are about nested objects ( Absinthe.Relay.Connection — absinthe_relay v1.6.0 ). Is there a way to implement root object pagination?
To exemplify my problem, I want this exact pagination
Most Liked
pierreabreup
Works like a charm!
connection field :contents, node_type: :content do
resolve fn
pagination_args, _ ->
Resolvers.Resources.Content.list(pagination_args)
|> Absinthe.Relay.Connection.from_list(pagination_args)
end
end
I’ve used Absinthe.Relay.Connection.from_list just for tests propose. The correct solution is to use from_slice
It is worth noting In this case, source: is unuseful, as you had predict. The source: is used when you are listing associated object ( Absinthe.Relay.Connection — absinthe_relay v1.6.0 )
object :person do
field :first_name, :string
connection field :pets, node_type: :pet do
resolve fn
pagination_args, %{source: person} ->
Absinthe.Relay.Connection.from_list(
Enum.map(person.pet_ids, &pet_from_id(&1)),
pagination_args
)
end
end
end
end
2
Popular in Questions
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lists...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Hi,
I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> somethi...
New
I have VueJS GUIs with the project generated using Webpack.
I have Elixir modules that will need to be used by the VueJS GUIs.
I forese...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
Other popular topics
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
Hello, how can I check the Phoenix version ?
Thanks !
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










