Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
How to provide and invalidate tags based on multiple query arguments

In my model a person can have multiple pets:

[
    {
        id: 1,
        name: 'liam',
        pets: [
            {
                id: 1,
                animal: 'cat',
            },
            {
                id: 2,
                animal: 'dog',
            }
        ]
    },
    {
        id: 2,
        name: 'keith',
        pets: [
            {
                id: 3,
                animal: 'spider',
            },
        ]
    },
]

I have implemented following api

const extendedApi = api.injectEndpoints({
    endpoints: (builder) => ({
      postPersonPet: builder.mutation({
        query: ({ personName, ...body }) => ({
          url: () => `/persons/${personName}/pets`,
          method: 'POST',
          body,
        }),
        // I want to invalidate pets of a specific personName
        invalidatesTags: (result, error, { personName }) => [{ type: 'PETS_TAG', personName: personName, id: `LIST` }],
      }),
      getPersonPets: builder.query({
        query: ({ personName }) => `/persons/${personName}/pets`,
        providesTags: (result, error, { personName }) => {
          if (!result) return [{ type: 'PETS_TAG', personName: personName, id: 'LIST' }]
  
          const tags = (result.length > 0) ?
            // I want provide tags of pets of a specific personName
            result.map((pet) => ({ type: 'PETS_TAG', personName: personName, id: pet.id }))
            :
            [{ type: 'PETS_TAG', personName: personName, id: 'LIST' }]
          return tags
        }
      }),
    }),
  })

When I create a new pet using POST /persons/liam/pets, I want to invalidate the pets of person with name liam. What's the correct way to do it?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!