0

I have a few react components that mutate my server data and for now I have refetchQueries: [{query:myQuery}]. I need to restructured the data as a map for faster lookup time. How can I accomplish this? In Redux, I would have used reselect and in MobX I would have used @computed. As far as I can tell, apollo doesn't support this functionality yet. I looked into:

  • @client directive, but this doesn't work for me since I have to compute the data on the server response.
  • reactive variables don't work either since I will have to change the variable everywhere I mutate the data, far from ideal.

There seems to be very little information out there about computed/derived values when using Apollo Client, the only reference I found was this one: Apollo GraphQl Storing derived data

Antuan
  • 501
  • 2
  • 6
  • 18

1 Answers1

0

How about if you define in your schema & in your resolver some alternative (union) response structure? (not sure if this would work actually)

type Query{
    books(mapBy:String): [Book]|JSON
}

so if you query (using it instead of mutation for simplicity)

query{
 books(mapBy:"id")
}

it would return JSON

{
  123: { __typename: "Book", name: "Dune"}
}

And if you don't want to return all of the Book fields in JSON, maybe pass extra param which would list actual structure you need.

Didn't encounter such problem myself yet, interesting. But otherwise, it should be done on client side.

Artjom Kurapov
  • 6,115
  • 4
  • 32
  • 42