is there a way in graphql to query just the most r...
# orm-help
h
is there a way in graphql to query just the most recently created object of a given type...without knowing anything about that item? Just "there are things and give me the most recent thing that was added"?
n
sort by creation date using orderBy
m
& limit 1?
h
but can I do that without a
where
?
I can sort and limit... but ideally i would call without a
where
argument... just "give me the latest"
m
You shouldn't need a
where
argument.
Do you mean 'no variables at all'?
h
well, right now I have this:
Copy code
return await context.db.query.thing({
        first: 1,
        orderBy: 'createdAt_DESC',
      })
m
That looks right to me, is it not working for you?
h
and what I get is
Copy code
"Variable \"$_where\" of required type \"ThingWhereUniqueInput!\" was not provided.",
m
Ah! Ok. I think I understand.
Instead of
thing
try
things
h
ahhhhhh
and just pull
[0]
from it
because.. yeah... it's a list
this makes sense =P
m
I would map over it 😉
Jussssst in case you decide to change it to return more than one item some day.
👍 1
h
fair enough
👍 1