question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useQuery doesn't notify for invalid queries on local state management

See original GitHub issue

Intended outcome: The Apollo client warns me that I’m using an invalid query/field while using the useQuery hook while dealing with local state

Actual outcome: It doesn’t display valuable information about the error. In fact, it displays nothing.

How to reproduce the issue: There’s a Sandbox for it. You can alternate between the working and broken version by toggling commented lines on the App component. Check the queries on queries.js… the field name doesn’t exist – the correct field is text, but I get no warning about that.

Versions

@apollo/react-hooks - 3.1.3
apollo-boost - 0.4.4
graphql - 14.5.8

Additional information

In the docs, it says:

“Client-side schema

You can optionally set a client-side schema to be used with Apollo Client, through either the ApolloClient constructor typeDefs parameter, or the local state API setTypeDefs method. Your schema should be written in Schema Definition Language. This schema is not used for validation like it is on the server because the graphql-js modules for schema validation would dramatically increase your bundle size. Instead, your client-side schema is used for introspection in Apollo Client Devtools, where you can explore your schema in GraphiQL.”

Which I think it kinda invalidates this issue report? The suggestion of a friend of mine would be to include graphql-js in development mode to notify the user and strip it out when bundling for production.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kevinjcolemancommented, May 17, 2020

@yss14 I set errorPolicy to all and I was able to access the error object.

  const { error, data } = useQuery(
    GET_STUFF,
    { errorPolicy: 'all' }
  )
    
  if (error) {
    console.log("error", error)
  }
1reaction
breathecommented, Nov 20, 2019

I’ve run into what I believe is the exact same issue – this is a seriously bad problem!

In my case – I’m wanting to use apollo local state. I modify an existing query by adding a @client field to it.

Suppose you do nothing and attempt to run a working app after making the above change. You will get a failure that provides zero information about the error.

Suppose you attempt to fix by stabbing in the dark at whatever black hole has sucked away all useful feedback about your issue. You know that you did something related to adding local state so you create typedefs, and resolvers, and add them to new ApolloClient({}) appropriately.

But there’s a bug in your resolver – and you are not returning a value for the new @client property. You get a failure with absolutely no information to help debug. You get such a failure even if the @client field is nullable btw.

Please please please, figure out how to provide useful information about this category of errors!

The lack of feedback to help debug queries with @client makes client side apollo state borderline unuseable.

"@apollo/react-hooks": "^3.1.3",
"apollo-boost": "^0.4.4",
"apollo": "^2.21.0",
Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries - Apollo GraphQL Docs
If all data is available locally, useQuery returns that data and doesn't query your GraphQL server. This cache-first policy is Apollo Client's default...
Read more >
What I learned from React-Query, and why I won't use it again
Our plan was to hold all server state in a React-Query cache, and access it via the useQuery hook. It looked good. Too...
Read more >
react-query: Refetch if and only if there is no error
On my root component, I have used use query to get the user details. but the problem is before I sign up or...
Read more >
React Query Error Handling | TkDodo's blog
This is certainly okay for some scenarios, but has a couple of drawbacks, too: It doesn't handle background errors very well: Would we...
Read more >
QueryClient | TanStack Query Docs
ensureQueryData is an asynchronous function that can be used to get an existing query's cached data. If the query does not exist, queryClient.fetchQuery...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found