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

Should ROOT_QUERY be initilized by myself ? #1804

Closed
darkship opened this issue Jun 19, 2017 · 3 comments
Closed

Should ROOT_QUERY be initilized by myself ? #1804

darkship opened this issue Jun 19, 2017 · 3 comments

Comments

@darkship
Copy link
Contributor

Hi,
I came across an issue like this #1701.

It appears that when I start my app I don't have any ROOT_QUERY. So that whatever is in my query,store.readQuery({query}); throws "Can't find field on object (ROOT_QUERY) undefined."
Running store.writeQuery({query, data}}) creates ROOT_QUERY and the same readQuery call works afterwards.

Is this a bug or should I have used initStore ?

@helfer
Copy link
Contributor

helfer commented Jun 20, 2017

Hi @darkship If any of the data that readStore tries to read is not there, the function will throw an error. In your case there's nothing in the store at all, which is why it errors at ROOT_QUERY. You should protect the readStore call with a try/catch block if it's possible that the data might not be in the store yet.

@helfer helfer closed this as completed Jun 20, 2017
@darkship
Copy link
Contributor Author

OK, thanks

@huan
Copy link

huan commented Mar 14, 2018

@helfer Why not just return null instead of throwing an Exception? I feel return null is more convenience.

@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

3 participants