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
Apollo misses populating properties when fragments are spread #7648
Comments
@pastelsky The issue here is that Apollo Client does not automatically know that The way to configure this information is by passing a const client = new ApolloClient({
cache: new InMemoryCache({
possibleTypes: {
CompatibleAtlassianProduct: [
// List of all known direct subtypes of CompatibleAtlassianProduct:
"CompatibleAtlassianDataCenterProduct",
// ...
],
},
}),
uri: "https://api.atlassian.com/graphql"
}); While you can mostly get away with manually listing only the subtypes that you actually need, you might want to generate |
Thanks @benjamn . I'll try this solution out. But regardless, I think it would be helpful to inform the user that a field type might not be resolvable using the currently available information and I found skipping of fields to be quite non-intuitive. |
@pastelsky I hear you, but giving a useful warning is difficult here, because you don't need |
I'm running into the same issue using inline fragments with an interface type. The query runs fine in graphiql or directly with the server, but not with apollo client. This is actually shown as an example in the union types section of graphql.org. Very similar to the example used for the documentation of possibleTypes. I'm just not understanding why resolving an interface type is a concern of the client to begin with. The client is naturally going to be worse at resolving these types than the server, and it's unclear to me why it needs to. I think it would help if the fragments section of the documentation gave an example of a feature where apollo client needs this information. In other words why can't apollo client just rely on the server and pass through the same data? What use cases are being affected by not having this information in the client? Explaining the requirements of apollo also explains the need for manual configuration or a process to automate it. Especially when data is being discarded executing an example from graphql.org, but works querying the server directly. |
I too have the same issue. I am using Query:
This is appolo client object
|
@parithibang I assume that your |
The creator type name is person only
So my possible types should be
|
@parithibang in that case, you do have a separate issue than the issue that was discussed here originally. Could you try to create a minimal reproduction for this and open a new issue? |
We are moving from a custom GraphQL client implementation (which does not mask fragment fields) to Apollo-client, and encountered this issue. I would like to echo @rsimp's arguments -- I am also not convinced that a GraphQL client should need to know possible types to resolve fragments in interfaces. The previous documentation for Apollo client v2 has more statements on why clients wants supertype-subtype relationship information, although the solution back in v2 was using Coming from a much simpler GraphQL client, I am not convinced by the reasons inside the documentation. Specifically,
For workarounds, we have:
I would like to know if it is possible to have an option that bypasses the fragment masking / matching behavior of |
Consider the following query —
Here, If I spread
Fragment1
instead of inlining properties, Apollo will not make the properties insideFragment1
(e.g.atlassianProduct
) available as data when usinguseQuery
.However, using the same query with a
fetch
POST request returns expected results.Intended outcome:
All fields inside the spread fragment should be visible in
data
Actual outcome:
All fields inside the spread fragment are ignored. However, If I inline properties of the fragment, expected results are obtained.
How to reproduce the issue:
See minimal reproduction —
https://codesandbox.io/s/apollo-graphql-fragment-bug-50yzl
Versions
3.3.x
The text was updated successfully, but these errors were encountered: