Query keys

ZZeph10/28/2022
Hi! I'm super new to TRPC and based on my understanding, TRPC has a thin wrapper around react query. So, I'm wondering how to include the query keys when using trpc.

Thank you!

export const itineraryRouter = router({
  list: publicProcedure
    .input(
      z.object({
        userId: z.string().uuid(),
      })
    )
    .query(async ({ input }) => {
      const itineraries = await prisma.itinerary.findMany({
        where: {
          userId: input.userId,
        },
      })
      return itineraries
    })
})

// how I use it in my component
const { data, isLoading } = trpc.itinerary.list.useQuery(
      {
        userId: user?.id as string,
      },
   
    {
      enabled: !!user,
    }
  )
A/Kalex / KATT10/28/2022
we do the query keys for you
A/Kalex / KATT10/28/2022
the above becomes

[['itinerary', 'list'], { where: { userId: x } }]
UUUnknown User10/28/2022
2 Messages Not Public
Sign In & Join Server To View
Eeyalll10/28/2022
is not necessary, just add the params. The queryKey is made for you.
UUUnknown User10/28/2022
Message Not Public
Sign In & Join Server To View
ZZeph10/29/2022
Thank you! Just to clarify, if i wanted to invalidate the queries, I would do this?
queryClient.invalidateQueries(['itinerary', 'list', {where: {userId: x}}
])
ZZeph10/30/2022
Oh.. totally missed this part of the docs! Thanks so much!