0

I have an Apollo Client that I'm using to request data from a service. I want to use the data I get in response to create a network of nodes and links e.g.

// Response data:
{
  "Team": [
    {
      "name": "Example Team",
      "members": [
        { "name": "Bob" },
        { "name": "Alice" }
      ]
    }
  ]
}

// Network data:
{
  "nodes": [
    { "name": "Example Team" }
    { "name": "Bob" },
    { "name": "Alice" }
  ],
  "links": [
    { "source": "Example Team", "target": "Bob" },
    { "source": "Example Team", "target": "Alice" }
  ]
}

Historically, before using GraphQL, I would have used Redux to store the munged API response in state and read from there.

Is it appropriate to take a GraphQL result from Apollo and immediately save it back to Apollo local state in a different form so it can be queried by components in that format?

The main problem I foresee is that I think I'd have to query to check if the data I want exists in local state, then make another query if it didn't. In a Redux-world this would be wrapped up inside my store which would then only make the request off to the API if it didn't have the data it needed which 'feels' much cleaner.

Tom
  • 2,734
  • 2
  • 22
  • 39

1 Answers1

0

In my case this could be solved using Afterware in Apollo Client, see this answer for more information.

It would allow me to munge the returned data into the form I need, and return it in the response alongside the original data.

Tom
  • 2,734
  • 2
  • 22
  • 39