apollo-link-state
apollo-link-state copied to clipboard
Fragments for mixed local/remote queries
I am trying to setup a query which fetches data both from the local cache and from the server. A problem arises when I introduce fragments, as the fragment used for my local query is sent to the server, which crashes the query.
query Query {
remoteObject {
...RemoteObjectFields
}
localObject @client {
...LocalObjectFields
}
}
fragment RemoteObjectFields on RemoteObject {
remoteField1
remoteField2
}
fragment LocalObjectFields on LocalObject {
localField1
localField2
}
This results in the server returning
errors = [
{ message: "No such type LocalObject, so it can't be a fragment condition", ... },
{ message: "Fragment LocalObjectFields was defined, but not used", ... }
]
Hardcoding the local fields as below works
query Query {
remoteObject {
...RemoteObjectFields
}
localObject @client {
localField1
localField2
}
}
fragment RemoteObjectFields on RemoteObject {
remoteField1
remoteField2
}
Is there a way to declare a fragment as local, or am I just missing something completely?
I think this is also a duplicate of https://github.com/apollographql/apollo-client/issues/3371
@silvainSayduck Have you found any viable workarounds for this?
Nope, still using hardcoded local fields...
In the soon to be released new version of this project, fragments that only have @client
fields / selection sets are automatically excluded from being sent to the server. So if you adjusted your local fragment definition like:
fragment LocalObjectFields on LocalObject {
localField1 @client
localField2 @client
}
it will be fully stripped before your query hits the server.
any update on this?
@hwillson Is there a PR I can contribute to?