Hello everyone (who's still awake!) -- are there w...
# prisma-whats-new
p
Hello everyone (who's still awake!) -- are there ways to "flatten" an array returned from a GraphQL query, if the number of items returned from that array is only 1, or every forcing only the first item of the array using
first: 1
and so reading it in javascript without using
item[0]
?
n
@picosam could you change your query to use
Type
instead of
allTypes
?
p
Hmm... so let's say I have the following query:
allUsers { photos (first: 1) { url } }
This can be invoked from the client as
user.photos[0].url
n
so do you know that
photos
of this user only contains one element?
oh nevermind, forget about that
p
Of course in this case, there's always going to be only
photos[0]
in that array... so my question is, can there be anyway to return this instead as, for example,
user.photoUrl
n
I've seen the pattern for the Relay API to flatten the
edge->node
structure using lodash
maybe a similar flatten approach could work here?
p
Let me google that... maybe apollo would have something similar
a
With apollo, you should be able to return photos[0] in a resolverMap, that will give you a single item in the result instead of an array
p
Thank you; I'll google that now, since googling flattening an array using apollo didn't turn anything out 🙂
Hello again @agartha — following back up on this; I’m actually unable to write a query using resolverMap that would do the trick… do you have an example lying around somewhere?