apollo-client-devtools icon indicating copy to clipboard operation
apollo-client-devtools copied to clipboard

When executing a @client query, result is not filtered to the selection set

Open vigie opened this issue 4 years ago • 10 comments

Intended outcome: Execute a @client query against local resolvers from GraphiQL and see in the result only the fields asked for in the query.

Actual outcome: The entire object as returned by the local resolver is displayed

How to reproduce the issue:

Create a local resolver to implement

type Query {
   foo: Bar
}

type Bar {
   a: int
   b: int
}

Execute query in GraphiQL

query {
   foo {
      a
   }
}

You will see both a and b fields returned in the result pane, instead of just a.

Note that the Apollo client itself does not suffer from this problem - that is, in code the result emitted by the observable will be correctly filtered based on the selection set.

This issue makes giving demos/trainings to show the flexible nature of GQL particularly frustrating.

Desktop (please complete the following information):

  • OS: Mac BIg Sur
  • Browser Chrome
  • Chrome version: 89.0.4389.90
  • Extension version: 3.0.2

vigie avatar Mar 22 '21 23:03 vigie

Thanks @vigie - any chance you could put together a small runnable reproduction that demonstrates this?

hwillson avatar Mar 28 '21 19:03 hwillson

We haven't heard back about a reproduction, so I'll close this for now (happy to re-open if anyone can provide a small runnable repro). Thanks!

hwillson avatar May 02 '21 18:05 hwillson

Sorry for the delay, I was on parental leave.

Here is a simple repo https://github.com/vigie/react-apollo-error-template

Let me know if you need more context. From the commit message of the above fork:

In Apollo dev tools, notice that the result of executing the following query includes people id, even though it was not asked for

query AllPeople {
  people @client {
    name
  }
}

However, put a breakpoint on line 19 of App.js and notice that the apollo client itself is correctly filtering out data not requested before returning it to the caller.

Apollo dev tools should do the same in its GraphiQL tab.

vigie avatar May 04 '21 00:05 vigie

Here is a screenshot of the problem as I see it, using the above repo:

Screen Shot 2021-05-03 at 5 47 44 PM

@hwillson can this be reopened for investigation now?

vigie avatar May 04 '21 00:05 vigie

Compare the above with the correct behavior of Apollo Client as inspected by Chrome debugger:

Screen Shot 2021-05-03 at 5 53 39 PM

vigie avatar May 04 '21 00:05 vigie

Now that I've added the required info, can this at least be re-opened for tracking purposes @hwillson ?

vigie avatar May 24 '21 22:05 vigie

@vigie sorry about that, re-opening. Thanks for the repro!

hwillson avatar May 26 '21 00:05 hwillson

I'd like to have a go at fixing this, @hwillson if you have any suspicions about the cause please let me know, thanks

vigie avatar Feb 23 '22 17:02 vigie

Hi @vigie ! From my local testing, it's looking like this issue has been resolved with the Apollo Studio integration introduced in DevTools 4.0.0. Are you still experiencing the issue? If not, I'll be happy to close this within a few days.

All the best, Emmanuel :-)

image Now matches the data result in the Chrome Debugger image

MrDoomBringer avatar Nov 01 '22 17:11 MrDoomBringer

Hi @MrDoomBringer

If you uncheck the "load from cache" option, you'll find that the issue still exists. Thanks for investigating.

vigie avatar Nov 01 '22 21:11 vigie