Comments (5)
Thanks for the feedback @BrentMifsud. We've had a lot of similar feedback from people on this feature, so you are not alone. We do intend to deprecate LocalCacheMutation
and allow you to make any selection set mutable in a future update.
In the mean time, the easiest way to work with this is to put the @apollo_client_ios_localCacheMutation
directive on the shared AnnouncementFragment
itself. You can use this fragment in a query, but it will also be usable for local cache mutations.
from apollo-ios.
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better.
from apollo-ios.
Thanks for the feedback @BrentMifsud. We've had a lot of similar feedback from people on this feature, so you are not alone. We do intend to deprecate
LocalCacheMutation
and allow you to make any selection set mutable in a future update.In the mean time, the easiest way to work with this is to put the
@apollo_client_ios_localCacheMutation
directive on the sharedAnnouncementFragment
itself. You can use this fragment in a query, but it will also be usable for local cache mutations.
@AnthonyMDev Thanks for the response.
Do you have any examples of this in practice? I have added the local cache mutation directive on my fragment, but there does not seem to be any option to insert a fragment.
// from graphqlclient
func updateCachedQuery<CacheMutation: LocalCacheMutation>(
cacheMutation: CacheMutation,
mutator: @escaping (inout CacheMutation.Data) -> Void
) {
store.withinReadWriteTransaction { transaction in
try transaction.update(cacheMutation) { selectionSet in
mutator(&selectionSet)
}
}
}
Here is my codegen config (in case im missing something):
{
"schemaName" : "Redacted",
"input" : {
"operationSearchPaths" : [
"Redacted/Modules/GraphQL/Fragments/*.graphql",
"Redacted/Modules/GraphQL/Mutations/*.graphql",
"Redacted/Modules/GraphQL/Queries/*.graphql"
],
"schemaSearchPaths" : [
"Redacted/Modules/GraphQL/schema.graphqls"
]
},
"output" : {
"testMocks" : {
"none" : {}
},
"schemaTypes": {
"moduleType": {
"embeddedInTarget": {
"name": "Redacted"
}
},
"path": "Redacted/Modules/GraphQL/Generated/"
},
"operations" : {
"inSchemaModule": {}
}
},
"options": {
"selectionSetInitializers" : {
"operations": true,
"namedFragments": true,
"localCacheMutations" : true
},
"deprecatedEnumCases": "include",
"schemaDocumentation": "include",
"warningsOnDeprecatedUsage": "include",
"conversionStrategies": {
"enumCases": "camelCase"
},
"pruneGeneratedFiles": true
}
}
from apollo-ios.
Ah, I see. This is still a bit difficult to do. Which is why we want to make the changes I mentioned above.
Check out the docs here. You'll want to use the updateObject(ofType:withKey:) function. Since you are actually trying to append the new announcement to a list of announcements, you'll want the
announcements` field in your mutable fragment.
fragment AnnouncementsListFragment @apollo_client_ios_localCacheMutation on Query {
announcements(locationId: $locationID) {
...AnnouncementFragment
}
}
When mutating the cache, you'll need to know the cache ID of the entity that has the announcements
field on it. But in your case, it's just on the root query, which has the cache key QUERY_ROOT
. You'll also need to pass in the correct locationID
variable.
Try this:
var myNewAnnouncement: AnnouncementFragment
store.withinReadWriteTransaction { transaction in
transaction.updateObject(
ofType: AnnouncementsListFragment.self,
withKey: "QUERY_ROOT",
variables: ["locationID": "myLocationID"]
) { (announcements inout AnnouncementsListFragment)
announcements.append(myNewAnnouncement)
}
}
There is definitely a lot to be desired with the current APIs for this. Hopefully this will get you where you need to be for now, but we definitely want to improve on this.
from apollo-ios.
Ahhh I see. I never thought of making an array into a fragment. Will try that.
from apollo-ios.
Related Issues (20)
- apollo-ios-codegen 1.8.0 CustomScalar is 'should not be edited.' HOT 2
- Variables Inside Fragments behaving oddly? HOT 14
- Invalid HTTP upgrade spams the log instead of returning an error HOT 10
- `asXXXXXXX` property on a union never returning `nil` if selection set empty HOT 4
- Add PrivacyManifest HOT 1
- Can't Use 2 Different Schemas in same Package HOT 2
- `SelectionSet` Generated Initializers Don't Compile with `self` Parameter HOT 5
- When using apollo-ios-pagination, there is an issue where data is not accurately updated when mutations occur. HOT 1
- Xcode Install CLI fails for versions >=1.8 HOT 10
- Test Issue HOT 1
- Testing author_association
- Process Mutation on a Queue when encountering network errors HOT 2
- WebSocketTransport: detect server side completion message. HOT 4
- Invalid type aliases generated on recursive types HOT 1
- The operation couldn’t be completed. (OSStatus error -9847.) HOT 11
- Cannot convert value of type 'GraphQLNullable<[String]>' to expected argument type '[String?]' HOT 10
- SchemaConfiguration.cacheKeyInfo(for:object:) never called? HOT 5
- Watcher not firing after failure to decode response HOT 2
- Cococapods installation should use download script to fetch CLI instead of using embedded binary
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo-ios.