I’m trying to build my own app by extrapolating from the Pragmatic Studio’s unpacked course material. They have a query for returning a list of “places” from the database in ascending order:
query do
@desc "Get a list of places"
field :places, list_of(:place) do
arg :limit, :integer
arg :order, type: :sort_order, default_value: :asc
arg :filter, :place_filter
resolve &Resolvers.Vacation.places/3
end
...
end
In my case I want to sort by the time an “article” was inserted. My schema is
schema "articles" do
field :body, :string
field :title, :string
belongs_to :user, Accounts.User
timestamps()
end
I’ve defined the article “object” in MyApp_Web/schema/schema.ex as
object :article do
field :id, non_null(:id)
field :body, non_null(:string)
field :title, non_null(:string)
field :user, non_null(:user), resolve: dataloader(Accounts)
field :inserted_at, non_null(:naive_datetime)
end
How do I structure the query to return a list of articles sorted by the inserted_at field?
When I try
query do
field :articles, list_of(article) do
arg(:user_id, non_null(:id)
arg(:order_by, :inserted_at)
resolve(&Resolvers.Article.articles/3)
end
end
I get told
In Order_by, :inserted_at is not defined in your schema.
but when I look in Graphiql the generated docs show insertedAt: NaiveDateTime!
for the Article type.