Hi guys, i want to make a feature of opened recent...
# prisma-whats-new
j
Hi guys, i want to make a feature of opened recent, anyone knows how i do that in a graphql schema? thx
a
@joao.santos Can you please explain a bit more about what you're trying to achieve?
👍 1
j
I have a Patients type in my schema, that have information inside, i wanted to make a component that showed the last 3 patients that were open recently...
d
@joao.santos that seems like a pretty basic requirement, no? You might consider having a run through the LearnApollo tutorials: https://www.learnapollo.com/
👍 1
j
i've already done that, dont remeber a similar case there, ill check it again, thx... And i know it must be basic, but i've started coding in the beggining of the year, i dont know much... thx again
d
@joao.santos do you know how to use dynamic query variables in gql queries?
j
yes...
d
I'm also new to the scene and so am just starting out similar to you. Assuming you know how to fetch data from graph.cool, it sounds like you just need help with sorting/filtering the data.
j
thats right
d
so, I would expect you need to write a function that sorts by creationDate, no?
j
but i dont want the create date, i want the last acces to the file
d
okay, so then you need to write a function that sorts by
updatedAt
?
j
yeah i waas talking now i thinkin about that
ok i have an idea how im going to do it
d
wait!
I'm new too so I'm still interested
j
thx so much, it helps talking about the problem
d
I assume you plan to run the function on the server side and not the client?
j
yeah im making in the client side first to test and then i'll make it in server..
never done in the server
d
me neither
can you show me your function along the way?
I'm interested to see how to actually apply the function as a filter
j
sure, maybe ill grab this in the weekend, tomorrow i have to work...
d
oh, I assumed you were working on it at the moment
well, ok --good luck
j
no, i came here and leaved the question hoping somene could indicate me to a similar casa until the weekend... i have family and work, i only come here 3 or 4 times a week to code..
i work in a dentist, it's a different business
lol
d
ok. If you remember, please msg me once you're working on it again
j
ok i'll do that, thx 😉
n
Hey @joao.santos
You can add a
lastOpened: DateTime
field on the
Patient
type
and just query first 3 patients when ordering by that field 🙂
j
So i think im going to make a field in the patient type of viewedAt, and every time i entered the patient ill send a mutation with a date, after the its only a matter of filtering the query by date... i think
ohh
hi nylan
nilan
n
Exactly like that! 🙂
d
is
lastOpened
a default field?
n
no
d
then why not use updatedAt ?
it already exists, no?
n
because it's something different
let's say, the patients status will be changed
that updates
updatedAt
but that doesn't necessarily mean that the patient has been opened/viewed, right?
j
right
if i do a query im not updating
n
🙂 I think this should work quite well
no, exactly
d
good point --I suppose we would need an
accessedAt
for that functionality
j
yeah i think it workes nice, ur lastOpened term is better also.. lol
n
haha I actually like
lastViewed
better
j
or that 😄
lol
thx guyas, in the weekend ill put here the resolution
now i have to make dinner.. 😄
n
awesome 🙂 glad to see you're making progress with the app!
looks like you've again learned a lot haha
j
i'll shatre it soon 😉
share
n
💯
j
i've been having some troubles passing data through components for dynamic queris, but now i pass it through react router... don know if its the propper way but its working
😄
have a good one guys
👍 1
d
@joao.santos this tutorial deals specifically with dynamic query variables through the router: https://www.learnapollo.com/tutorial-react/react-03
👍 1
j
i've done that in the beggining of the year, i thought it was trough props... but ok, ill check it..
hey @nilan good morning, i spent the night thinking of this, so i decided to use a functions in your service, so i did this
Copy code
module.exports = function (event) {
  event.data.lastViewed = event.data.updatedAt
  return {data: event.data}
}
and everytime i see a patientProfile i have a field of viewCount that is updated, and everytime that its updated he returns that function... In the tests works and he returns the date but now when i make a mutation, the field stays null... Is this thew right way to do server side? I also use date-now package in the function but the value that it returns was not a date...lol i don know... thx
i know its redundant i could use updateAt only, and sort it, but i really wanted a different date, but i couldnt use tha date-now package...
n
@joao.santos you can say:
Copy code
event.data.lastViewed = new Date().toISOString()
I wonder why you want to do this in a server-side function and not in a normal mutation 🙂
j
yeah, my idea was to run the function whith a query, but u only have the option to created updated or deleted... so i was ahead of myself there... lol im still not good thinking in code...
n
So in your application, I assume there is a button that leads to the view where the patient is "being viewed", right?
j
thx for that line of code... 😄 just learned another thing..
yeah thats right viewProfile
component
n
ok
so in that component you can send a mutation
that updates the patient
j
yeah thats about it.. lol
im making a viewCount, at least i take something out of the mutation