Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 4c8d0b9

Browse files
author
Enda Phelan
committed
docs: add datasyncplugin usage guide
1 parent 9509194 commit 4c8d0b9

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

docs/datasync/delta-queries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ In the [`src/index.ts`](https://github.com/aerogear/graphback/blob/templates-rel
9797
import { createDataSyncAPI } from '@graphback/datasync'
9898

9999

100-
const { typeDefs, resolvers, contextCreator } = createDataSyncAPI(modelDefs, { db });;
100+
const { typeDefs, resolvers, contextCreator } = createDataSyncAPI(modelDefs, { db });
101101
```
102102
The data sources provided by `createDataSyncAPI` ensure that:
103103
- The documents are always soft deleted

docs/datasync/intro.md

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,61 @@ npm install @graphback/datasync
3232

3333
## Usage
3434

35-
In order to use data synchronization features, there are two steps to be followed:
35+
Add annotations to your data models:
3636

37-
- Add metadata to schema
38-
- Use `createDataSyncAPI` to create the API using Graphback
37+
```graphql
38+
"""
39+
@model
40+
// highlight-next-line
41+
@datasync
42+
"""
43+
type User {
44+
id: _GraphbackObjectID
45+
name: String
46+
}
47+
```
48+
49+
The preferred and simpest way to add data sync functionality is to use the `createDataSyncAPI` function which wraps `buildGraphbackAPI`:
50+
51+
```ts
52+
import { createDataSyncAPI } from '@graphback/datasync'
53+
54+
const { typeDefs, resolvers, contextCreator } = createDataSyncAPI(modelDefs, { db });
55+
```
56+
57+
Alternatively, you can use the default [`buildGraphbackAPI`](../getting-started/adding-graphback-to-your-project.md#configure-graphback) and add the `DataSyncPlugin` plugin directly:
58+
59+
```ts
60+
import { buildGraphbackAPI } from 'graphback';
61+
import { DataSyncPlugin } from '@graphback/datasync'
62+
63+
const { typeDefs, resolvers, contextCreator } = buildGraphbackAPI(schema, {
64+
...,
65+
plugins: [
66+
new DataSyncPlugin({
67+
enabled: true
68+
})
69+
]
70+
});
71+
```
72+
73+
Or if you are invoking the plugin with `graphback generate`:
74+
75+
```yaml title=".graphqlrc"
76+
schema: './src/schema.graphql'
77+
documents: './client/src/graphql/**/*.graphql'
78+
extensions:
79+
graphback:
80+
# path to data mode file(s)
81+
model: './model/datamodel.graphql'
82+
plugins:
83+
...
84+
graphback-datasync:
85+
packageName: '@graphback/datasync' # required to dynamically load
86+
conflictConfig:
87+
models:
88+
Note:
89+
enabled: true
90+
```
3991
40-
For a more in-depth guide to setting up data synchronization features, check [this](delta-queries.md) page.
92+
For a more in-depth guide to setting up data synchronization features, check [this](delta-queries.md) page.

docs/releases.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Please follow individual releases for more information.
2626
* Prevent creation of empty `Subscription`, `Query`, `Mutation` resolver objects ([#2073](https://github.com/aerogear/graphback/pull/2073), fixed by [97e826](https://github.com/aerogear/graphback/commit/97e82677257b54783916c3062ed6f0e74f25c038))
2727
* Configure relationship auth rule with field instead of database key ([#2101](https://github.com/aerogear/graphback/pull/2073), fixed by [525bc9a](https://github.com/aerogear/graphback/commit/525bc9a641fa7cb1818a0727a675564e6fa12dda))
2828
* Fix `Could not find a declaration file for module 'bson'` error ([#2104](https://github.com/aerogear/graphback/pull/2104), fixed by [4f9ce7c](https://github.com/aerogear/graphback/commit/4f9ce7c2d6c494b33f447e1b4d6a47fbd880f353))
29+
* Add missing interface ([#2019](https://github.com/aerogear/graphback/pull/2109), fixed by [f46e920](https://github.com/aerogear/graphback/commit/f46e9200def565b0b0e34ccc13f7efa50f346550))
2930

3031
### Breaking Changes
3132

0 commit comments

Comments
 (0)