brick
brick copied to clipboard
**Migrating to Brick 2 from Brick 1**
Brick 2 focuses on Brick problems encountered at scale. While the primary refactor was the abstraction of domain-specific code from generalized domains, this major release also includes a new GraphQL domain, resolution of community pain points, and a few neat tricks.
Please follow the guide below to mitigate the breaking changes (shell commands are run at your own risk).
And please respond to this issue or open a new one if you have any difficulty.
Breaking Changes
- Brick no longer expects
lib/app; it now expectslib/brick.mv -r lib/app lib/brick - Models are no longer discovered in
lib/app/models; they are now discovered via*.model.dart. They can live in any directory withinliband have any prefix. (#38)for FILENAME in lib/brick/models/*; do mv $FILENAME "${FILENAME/dart/model.dart}"; done brick_offline_firstis now, fundamentally,brick_offline_first_with_rest.brick_offline_firstnow serves as an abstract bedrock for offline domains.sed -i '' 's/brick_offline_first:/brick_offline_first_with_rest:/g' pubspec.yaml for FILE in $(find "lib" -type f -name "*.dart"); do sed -i '' 's/package:brick_offline_first/package:brick_offline_first_with_rest/g' $FILE; donebrick_offline_first_abstractis nowbrick_offline_first_with_rest_abstractsed -i '' 's/brick_offline_first_abstract:/brick_offline_first_with_rest_abstract:/g' pubspec.yaml for FILE in $(find "lib" -type f -name "*.dart"); do sed -i '' 's/package:brick_offline_first_abstract/package:brick_offline_first_with_rest_abstract/g' $FILE; donerestproperties have been removed fromOfflineFirstException. UseOfflineFirstWithRestExceptioninstead frombrick_offline_first_with_rest.OfflineFirstRepository#get(requireRemote:andOfflineFirstRepository#getBatched(requireRemote:has been removed. Instead, usepolicy: OfflineFirstGetPolicy.alwaysHydrateOfflineFirstRepository#get(hydrateUnexisting:has been removed. Instead, usepolicy: OfflineFirstGetPolicy.awaitRemoteWhenNoneExist(this is the default).OfflineFirstRepository#get(alwaysHydrate:has been removed. Instead, usepolicy: OfflineFirstGetPolicy.alwaysHydrate.
Fun Changes
- Utilize
OfflineFirstDeletePolicy,OfflineFirstGetPolicy, andOfflineFirstUpsertPolicyto override default behavior. Specific policies will throw an exception when the remote responds with an error (and throw that error) or skip the queue. Existing default behavior is maintained. OfflineFirstRepository#deletenow supports requiring a successful remote withOfflineFirstDeletePolicy.requireRemote. If the app is offline, normally handled exceptions (ClientExceptionandSocketException) arerethrown. (#182)OfflineFirstRepository#upsertnow supports requiring a successful remote withOfflineFirstUpsertPolicy.requireRemote. If the app is offline, normally handled exceptions (ClientExceptionandSocketException) arerethrown.
Seven New Packages
brick_graphql. TheGraphqlProviderinterfaces with a GraphQL backend. It uses gql's Link system to integrate with other community-supported functionality. That, and all your variables are autogenerated on every request.brick_graphql_generators. The perfect companion tobrick_graphql, this thin layer aroundbrick_rest_generatorsbattle-tested core compiles adapters for the GraphQL domain.brick_json_generators. The experienced core separated frombrick_rest_generatorspermits more code reuse and package creation for JSON-serving remote providers.brick_offline_first_build. Abstracted from the experienced core ofbrick_offline_first_with_rest_build, these helper generators and utils simplify adding offline capabilites to a domain.brick_offline_first_with_graphql. Utilize the GraphQL provider with SQLite and Memory cache. This is a near mirror ofbrick_offline_first_with_rest, save for a few exceptions. First, the OfflineQueueLink must be inserted in the appropriate position in your client's Link chain. Second,OfflineFirstWithGraphqlRepository#subscribepermits streaming updates, including notifications after local providers are updated.brick_offline_first_with_graphql_abstract. Annotations for the GraphQL domain without including Flutter.brick_offline_first_with_graphql_build. The culmination ofbrick_graphql_generatorsandbrick_offline_first_build.