š useQuery doesn't work when there is both a @client directive and a normal query together
See original GitHub issueHow to reproduce the issue:
- Create a query with both a
@client
directive (with an alias) and a normal query together, eg:
query GroupsTableQuery($organizationId: ID!) {
clientOrganization: organization(id: $organizationId) @client {
planType
}
organization(id: $organizationId) {
groups {
id
name
}
}
}
- Use it:
const { data, loading, error } = useQuery(GroupsTableQuery, {
variables: { organizationId },
});
Intended outcome:
- The server correctly returns
data
withgroups
,id
andname
. - Apollo resolves the
@client
directive. useQuery
returns{ data }
with bothclientOrganization
andorganization
.
Actual outcome:
- The server correctly returns
data
withgroups
,id
andname
. ā - Apollo doesnāt resolve the
@client
directive. ā useQuery
returns{ data }
asundefined
. ā
Obs:
If I have two separate queries, everything works as expected (so I know there is nothing wrong with my queries). Eg:
query ClientGroupsTableQuery($organizationId: ID!) {
clientOrganization: organization(id: $organizationId) @client {
planType
}
}
query GroupsTableQuery($organizationId: ID!) {
organization(id: $organizationId) {
groups {
id
name
}
}
}
PS: You might be wondering why I have an organization
thatās resolved on the client and another thatās resolved on the server, and this is because weāre slowly migrating our BE to GraphQL, so parts of the data is resolved on the client through our Rest API.
Versions
System:
OS: macOS 10.15.5
Binaries:
Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
Yarn: 1.22.4 - ~/.yarn/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.15.3/bin/npm
Browsers:
Chrome: 84.0.4147.89
Edge: 84.0.522.40
Firefox: 78.0.2
Safari: 13.1.1
npmPackages:
@apollo/client: ^3.0.0-beta.41 => 3.0.0-beta.41
@apollo/link-error: ^2.0.0-beta.3 => 2.0.0-beta.3
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Local resolvers - Apollo GraphQL Docs
This query includes a mixture of both remote and local fields. isInCart is the only field marked with an @client directive, so it's...
Read more >React Apollo: Understanding Fetch Policy with useQuery
I've been working on an Apollo client project these days. ... A cache-only query throws an error if the cache does not contain...
Read more >Redux to Apollo: Data Access Patterns - NerdWallet
When Apollo encounters a field marked with the client directive, it knows not to send that field over the network and instead resolve...
Read more >Introduction to queries - Microsoft Support
An Access query is very versatile and can pull information from various tables and assemble it for display in a form or report....
Read more >Using REST API with Apollo Client by Avi Takiyar
In this tutorial, it is demonstrated how a REST API can be used in our React/NextJS app using Apollo Client and our already...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Seeing the same issue on Apollo Client 3.0.2. In my case the query resolves correctly and the graphql call returns correct data when watching the Network tab in dev tools. However, ādataā is still returned as āundefinedā. Removing the field with @client fixes it and have confirmed the @client field Iām using works on itās own.
It doesnāt sound like there is an outstanding issue here, so closing. Thanks!