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

query() returns null-data #3519

Closed
blissi opened this issue May 27, 2018 · 4 comments
Closed

query() returns null-data #3519

blissi opened this issue May 27, 2018 · 4 comments

Comments

@blissi
Copy link

blissi commented May 27, 2018

Hallo,
I've got an Angular app and today updated from Angular Client 2.2.2 to the latest version 2.3.1. Suddenly, queries don't work anymore. For example, the following small code snippet always results in:

{
    data: null,
    loading: false,
    networkStatus: 7,
    stale: true
}

Here is the snippet:

export class HomeComponent {
	constructor(private apollo: Apollo) {
	}
	
	public onTestButton(): void {
		const client = this.apollo.getClient();
		client.query({
			query: gql`
				query GetCountries {
					countries {
						_id
						name
					}
				}
			`,
			fetchPolicy: "network-only"
		})
		.then(data => console.dir(data))
		.catch(error => console.error(error));
	}
}

Is this a known issue? I debugged into Apollo Client and I could see that the real data was actually received in QueryManager.fetchRequest, but from that point on the code is rather complicated for a starter like me.

Further info: with fetch policy "no-cache" the data is correctly returned.

@blissi
Copy link
Author

blissi commented May 28, 2018

I found out that the complete-field of the newData-field of the query is set to false. The only place where this is set seems to be in the fetchRequest()-function:

                        if (fetchPolicy !== 'no-cache') {
                            try {
                                _this.dataStore.markQueryResult(result, document, variables, fetchMoreForQueryId, errorPolicy === 'ignore' || errorPolicy === 'all');
                            }
                            catch (e) {
                                reject(e);
                                return;
                            }
                        }
                        else {
                            _this.setQuery(queryId, function () { return ({
                                newData: { result: result.data, complete: true },
                            }); });
                        }

Thus, this is only set for fetch policy "no-cache".

The code that evaluates the complete-field is isMissing = !newData.complete ? !newData.complete : false; in queryListenerForObserver.

Any idea?

@hwillson
Copy link
Member

Any chance you could put together a small runnable reproduction for this? That would greatly help with troubleshooting. Thanks!

@blissi
Copy link
Author

blissi commented Jun 19, 2018

I'm sorry, I didn't close this issue...it was a problem on my machine: for some reason graphql-tools wasn't updated and caused big trouble.

@blissi blissi closed this as completed Jun 19, 2018
@jdorleans
Copy link

I believe you might had encountered the problem I described here: #3030 (comment)

@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.
Projects
None yet
Development

No branches or pull requests

3 participants