Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(graphcache) - Expose data on write and writeOptimistic results #613

Merged
merged 2 commits into from
Mar 13, 2020

Conversation

kitten
Copy link
Member

@kitten kitten commented Mar 13, 2020

This is potentially a missing piece to use Graphcache to fully simulate a schema.
When simulating queries, they can be written using write and queried using query.

To simulate mutations we currently only have writeOptimistic + opts.optimistic + opts.updates to generate a mutation result from scratch. To get around this one would need the writeOptimistic result.

This can then be enriched, e.g.:

import { createRequest } from '@urql/core';
import { writeOptimistic, query, write } from '@urql/exchange-graphcache';

const store = new Store(/* ... */);

/** This would fully simulate a mutation using optimistic updates, queries so that resolvers can update the data, then writes it back permanently, assuming that the resolvers return serialisable data. */
const mutation = (query, variables) => {
  const request = createRequest(query, variables);
  const result = writeOptimistic(store, request, request.key);
  result.data = query(store, request, result.data).data;
  result.data = write(store, request, result.data).data;
  return result;
};

@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2020

🦋 Changeset is good to go

Latest commit: 13a089c

We got this.

This PR includes changesets to release 1 package
Name Type
@urql/exchange-graphcache Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kitten kitten merged commit 717b956 into master Mar 13, 2020
@kitten kitten deleted the fix/expose-write-data branch March 13, 2020 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants