Skip to content
This repository has been archived by the owner on Jul 10, 2019. It is now read-only.

Code works on codesandbox, but not on my machine #187

Closed
akiran opened this issue Jan 30, 2018 · 11 comments
Closed

Code works on codesandbox, but not on my machine #187

akiran opened this issue Jan 30, 2018 · 11 comments

Comments

@akiran
Copy link
Contributor

akiran commented Jan 30, 2018

Hi,

I am creating different examples to explore local state management with apollo. Recently, I am running into an issue where similar code work in one repo but fails in another repo.

I created a codesandbox to demostrate this issue.
Code works in this codesandbox.
https://codesandbox.io/s/v00rnlkr20
Button toggles between login and logout when we click on it.

But if I download the codesandbox code and run it on my machine, it fails with error
screen shot 2018-01-30 at 7 09 14 pm

To make sure, it is not a problem with my machine, I requested my colleague to download code and run it on his machine. It doesn't work on his machine also, but it works on codesandbox.

@LawJolla
Copy link

LawJolla commented Jan 30, 2018

I continue to struggle with the same issue. I think there's a dedupe problem somewhere in the chain.

{
    "apollo-cache-inmemory": "^1.1.5",
    "apollo-cache-persist": "^0.1.1",
    "apollo-client": "^2.2.1",
    "apollo-link": "^1.0.7",
    "apollo-link-context": "^1.0.3",
    "apollo-link-error": "^1.0.3",
    "apollo-link-http": "^1.3.2",
    "apollo-link-state": "^0.3.1",
    "apollo-utilities": "^1.0.5",
    "react-apollo": "^2.0.4"
}

I get the same error. Put if I remove the carrots and pin all of the versions (and delete node_modules and lock files), it works fine. Of course the odd part is that all of those versions are the most current.

@kavink
Copy link

kavink commented Jan 30, 2018

@LawJolla @akiran I am facing the same issue... I cannot understand what magic is going wrong, deleting lock files and node_modules has not helped. I see an issue where defaults in Apollo-link-state do not seem to actually set default in @client namespace in local cache, Please can you see what your local data with defaults looks like ?

@kavink
Copy link

kavink commented Jan 30, 2018

@peggyrayzis ^^ I think I found the issue. Defaults are not working on my local machine. dev environment: Mac OS.

@LawJolla
Copy link

The defaults seem like they don't work because the @client directive is not working so the query blows up. (I think)

Try rolling your modules back and clear your NPM cache. I went with

 {
   "apollo-client": "2.0.4",
   "apollo-cache-inmemory": "1.1.0",
  "apollo-utilities": "1.0.3"
}

@pachomski
Copy link

pachomski commented Jan 30, 2018

Having the same issue. Was working fine this morning before I npm installed :(.

Was able to get it working the following versions. Thanks @LawJolla for saving the day!

// package.json

{
        "apollo-link": "1.0.7",
        "apollo-client": "2.0.4",
        "apollo-cache-inmemory": "1.1.0",
        "apollo-utilities": "1.0.3",
        "apollo-link-http": "1.3.2",
        "apollo-link-state": "0.3.1"
}

@kavink
Copy link

kavink commented Jan 30, 2018

@pachomski yeah.. its a huge bug.. thats what happened to me . see workaround I just posted... #188

@LawJolla That does not work.. I finally found a workaround after spending like 12 hours...

@pachomski
Copy link

@kavink,

Unfortunately your fix in #188 did not work for me. While it set the default state, the mutations I had in place were not firing

@kavink
Copy link

kavink commented Jan 30, 2018

@pachomski You also need to change your mutation data, to do the same... i.e.

const data = {
    'env@client': {
    .....
   }
}

I just got both mutations and query working with that trick in withClientState

@peggyrayzis
Copy link
Contributor

peggyrayzis commented Jan 30, 2018

The CodeSandbox isn't working locally for me either. I think it's because apollo-client@2.2.1 is installing the latest patch version of apollo-utilities, which is broken. A lot of our packages depend on apollo-utilities, so it's likely that apollo-link-state is installing the latest patch too.

As for a fix, we're hoping to resolve the cause of the bug in apollo-utilities very soon.

@akiran
Copy link
Contributor Author

akiran commented Feb 2, 2018

Error is happening because of this line https://github.com/apollographql/apollo-link-state/blob/master/packages/apollo-link-state/src/index.ts#L76
resolverMap is undefined.
so error is thrown because of resolverMap[fieldName] access

@peggyrayzis
Copy link
Contributor

Upgrading to the latest versions of apollo-cache-inmemory and apollo-link-state should now fix this issue! Thank you all for your patience 😀

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

5 participants