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

InMemoryCache.writeData doesn't respect custom scalar data #4554

Closed
vvakame opened this issue Mar 8, 2019 · 2 comments
Closed

InMemoryCache.writeData doesn't respect custom scalar data #4554

vvakame opened this issue Mar 8, 2019 · 2 comments

Comments

@vvakame
Copy link

vvakame commented Mar 8, 2019

Intended outcome:

My GraphQL schema has scalar JSON.
and, It contains object and array.
My application has a below steps.

  1. user choose data (it contains schema-less JSON data) from the list.
  2. user will modify the data and submit it to server.

I made reproduction code. https://codesandbox.io/s/o4r2lk7nmz

I'm reading https://www.apollographql.com/docs/graphql-tools/scalars.html .
It explains server side implementations, but client side is not.

Actual outcome:

  1. user choose data (it contains schema-less JSON data) from the list.
  2. user will modify the data and submit it to server.

I implement step 1 by GraphQL query (fetch list from server) and mutation (update local state by @client mutation).
I used cache.writeData to hold data that is selected by user.
but cache.writeData can't handling scalar JSON data.

Uncaught (in promise) Invariant Violation: Missing selection set for object of type undefined returned for query field data
    at new InvariantError (https://o4r2lk7nmz.codesandbox.io/node_modules/ts-invariant/lib/invariant.js:16:28)
    at assertSelectionSetForIdValue (https://o4r2lk7nmz.codesandbox.io/node_modules/apollo-cache-inmemory/lib/bundle.cjs.js:463:90)
    at StoreReader.executeField (https://o4r2lk7nmz.codesandbox.io/node_modules/apollo-cache-inmemory/lib/bundle.cjs.js:401:13)
    at eval (https://o4r2lk7nmz.codesandbox.io/node_modules/apollo-cache-inmemory/lib/bundle.cjs.js:350:55)

I found some suspicious parts.

queryFromPojo doesn't respect for custom scalar type.

I tried use cache.writeData with id, but this code can't get result. because I want to write data to it, but this code runs before write.
and this code overwrite my __typename by __ClientData always.
cache.writeData ignore my request silently.

How to reproduce the issue:

https://codesandbox.io/s/o4r2lk7nmz
↑ PRESS EXECUTE MUTATION button

Versions

  System:
    OS: macOS 10.14.3
  Binaries:
    Node: 11.10.1 - ~/.nodebrew/current/bin/node
    Yarn: 1.13.0 - ~/.nodebrew/current/bin/yarn
    npm: 6.7.0 - ~/.nodebrew/current/bin/npm
  Browsers:
    Chrome: 72.0.3626.121
    Firefox: 62.0
    Safari: 12.0.3
  npmPackages:
    apollo-cache-inmemory: ^1.5.1 => 1.5.1
    apollo-client: ^2.5.1 => 2.5.1
    apollo-link: ^1.2.8 => 1.2.9
    react-apollo: ^2.5.1 => 2.5.2
@vvakame
Copy link
Author

vvakame commented Mar 10, 2019

I found the work around.

I read this article carefully again.
https://www.apollographql.com/docs/react/advanced/caching.html#writequery-and-writefragment
https://www.apollographql.com/docs/react/advanced/caching.html#cacheRedirect
I avoid to use cache.writeData and use cache.writeQuery, cache.writeFragment, cacheRedirects option.

This issue still remains.

@hwillson
Copy link
Member

writeData has been removed from Apollo Client 3. For the full details, see: #5923

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants