Hi All, I'm saving a list of ids to a `Type.otherT...
# prisma-whats-new
p
Hi All, I'm saving a list of ids to a
Type.otherTypeIds
as an array by executing
mutation
. Is there a way to fetch (query) items of
OtherType
in the order specified in the array?
d
Don't know if I understood you, but I think you could order them by field, such as the automatic `createdAt`field that comes with every newly created record. https://www.graph.cool/docs/reference/graphql-api/query-api-nia9nushae#ordering-by-field
p
@Dukuo I don't want to sort them (order By)
I make custom order in my GUI and I'd like to read them from graph ql in the same order
d
your
Type
would still need to have a custom sort field, which I believe you already have
p
@Dukuo Thanks for suggestions but it's not a problem on UI, the problem is tha I recieve items of type
OtherType
already in some order from GraphCool.
d
would you mind sharing your query? now i'm just curious of what you are trying to achieve
p
@Dukuo and I want to have mu custom order, which is an order of ids I provided in save / update mutation of type
Type
I will use some fake example but more clear
there is
Client
type and
Address
type. Client can have many `Address`es
business rule is that first address is *primary *
(this is a little bit stupid example because I would just add field
primary
in
Address
type but in my real case I don't want to do that)
d
i'm following
p
and now I have in GUI dynamic component when i can reorder addresses, let say Customer
Google
have 3 addresses assigned
and my solution is that the first
address
on GUI list is primary one
now I take order from GUI and provide
Address
ids in the same order
for example ids of adressses make up an array
[23,55,2]
which means that address with ID = 23 is the primary one
d
okay I think I got the idea
but the way you are implementing it is error prone IMO
p
it is saved into GraphCool with that order, however when I read it is get adress with ID===2 as the first one
d
I would store a custom order field in each field
wouldn't hurt performance, and it wouldn't be array-dependant
p
yes, I mentioned that above, however for some reasons I don't want to do it
d
could you elaborate on why ?
p
mainly because I whould have to add new intermediate type
d
but it would solve your problem and it would not be graphcool-query-array dependant
p
what's interesting in the DATA section on webconsole I can see that IDs are in the order I've created on GUI
d
Maybe @nilan can help us. How's the deal with querying for a
Type
and the resulting record order?
p
that's true, but from trivial it immediately gets to medium size and from business point of view it's not as important
d
the thing is that if you are ordering by ID I would assume the order you are seeing in the console is the order you created the records
(which I would also assume is being ordered by
createdAt
)
since you are not managing the record's order within the console
(I might be mistaken tho)
p
the thing is I don't use any
orderBy
by they are sorted by
createdAt
which is default on I assume
one
d
yeah, that's the thing. Your records are currently being ordered by the
createdAt
field, not the ID sorting you are managing
because that would require a field to order by
which in your current implementation case (or at least what I understood that you are doing) is the
ID
field
am I correct in the last statement ?
p
yes, but that order is already there, as the order of elements in an array of
Customer.addresses
field
d
yeah but that order was when you newly created those 3 records of your example
it's not an order you can further manage if you don't have a custom ordering field
that's what i'm trying to say
p
I can!
d
then how are you currently doing it! hahah
this is getting confusing, but i'm really trying to understand you
p
that's the point if you go to DATA section in GraphCool console you can see it is correct
d
yeah but how in the world are you ordering them in your current implementation ?
like, how are being ordered right now
p
Can I past image into this chat?
d
sure, you can copy the image to your clipboard and simply paste it in the textbox
p
don't work
d
woops, you are right
p
{ allProfiles { profileName skills(orderBy: null) { id name } } }
d
that's your current way of doing it ?
p
simplified
and results
d
well that
orderBy: null
is so suspicious
p
{ "data": { "allProfiles": [ { "profileName": "Oracle Developer", "skills": [ { "id": "cj6nne3td1um60191sdqowwp0", "name": "SQL" }, { "id": "cj6nniqcj1upu0191q5dxswju", "name": "PL SQL" } ] },
this
orderBy
doesn't do anything actually
d
I would assume that it's still ordering by some field, which I don't think is the ordering you are trying to do.
I would still suggest you use a custom ordering field, although I know it's not the solution you are looking for
p
Probably with more time I will
thank's for you time
d
oh np at all, thanks for your patience
if I find something useful for this case i'll come back
p
thanks a lot
🦜 1