@ttoss/graphql-api 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -5
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ This package provides an opinionated way to create an GraphQL API using ttoss ec
|
|
|
14
14
|
pnpm add @ttoss/graphql-api graphql
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## Usage
|
|
18
18
|
|
|
19
19
|
This library uses [`graphql-compose`](https://graphql-compose.github.io/) to create the GraphQL schema. It re-export all the [`graphql-compose`](https://graphql-compose.github.io/) types and methods, so you can use it directly from this package.
|
|
20
20
|
|
|
@@ -49,6 +49,8 @@ This library uses the `tsconfig.json` file from the target package it is being a
|
|
|
49
49
|
|
|
50
50
|
### Resolvers
|
|
51
51
|
|
|
52
|
+
TODO
|
|
53
|
+
|
|
52
54
|
### Integrate All Modules
|
|
53
55
|
|
|
54
56
|
Once you've created all your types and resolvers, you can integrate all the modules to create the GraphQL schema.
|
|
@@ -73,7 +75,7 @@ Method `composeWithRelay` will handle the object identification for your `Object
|
|
|
73
75
|
|
|
74
76
|
Method `composeWithRelay` only works if `ObjectTypeComposer` meets the following requirements:
|
|
75
77
|
|
|
76
|
-
1. Has defined `recordIdFn
|
|
78
|
+
1. Has defined [`recordIdFn`](https://ttoss.dev/blog/2024/01/12/working-with-different-ids-through-the-application#record-id): returns the id for the [`globalId`](/blog/2024/01/12/working-with-different-ids-through-the-application#global-id) construction. For example, if you use DynamoDB, you could create id from hash and range keys:
|
|
77
79
|
|
|
78
80
|
```ts
|
|
79
81
|
UserTC.setRecordIdFn((source) => {
|
|
@@ -81,7 +83,7 @@ Method `composeWithRelay` only works if `ObjectTypeComposer` meets the following
|
|
|
81
83
|
});
|
|
82
84
|
```
|
|
83
85
|
|
|
84
|
-
|
|
86
|
+
1. Have `findById` resolver: this resolver will be used by `RootQuery.node` to resolve the object by [`globalId`](/blog/2024/01/12/working-with-different-ids-through-the-application#global-id). Also, add the `__typename` field is required by Relay to know the type of the object to the `node` field works. For example:
|
|
85
87
|
|
|
86
88
|
```ts
|
|
87
89
|
UserTC.addResolver({
|
|
@@ -97,6 +99,12 @@ Method `composeWithRelay` only works if `ObjectTypeComposer` meets the following
|
|
|
97
99
|
});
|
|
98
100
|
```
|
|
99
101
|
|
|
102
|
+
1. Call `composeWithRelay` method: this will add the `id` field and the `node` query. For example:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
composeWithRelay(UserTC);
|
|
106
|
+
```
|
|
107
|
+
|
|
100
108
|
#### Example
|
|
101
109
|
|
|
102
110
|
```ts
|
|
@@ -134,9 +142,13 @@ UserTC.addResolver({
|
|
|
134
142
|
args: {
|
|
135
143
|
id: 'String!',
|
|
136
144
|
},
|
|
137
|
-
resolve: ({ args }) => {
|
|
145
|
+
resolve: async ({ args }) => {
|
|
138
146
|
const { type, recordId } = fromGlobalId(args.id);
|
|
139
|
-
|
|
147
|
+
const user = await query({ id: recordId });
|
|
148
|
+
return {
|
|
149
|
+
...user,
|
|
150
|
+
__typename: UserTC.getTypeName(), // or 'User';
|
|
151
|
+
};
|
|
140
152
|
},
|
|
141
153
|
});
|
|
142
154
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/graphql-api",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "A library for building GraphQL APIs using ttoss ecosystem.",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"ts-node": "^10.9.2",
|
|
43
43
|
"tsconfig-paths": "^4.2.0",
|
|
44
44
|
"yargs": "^17.7.2",
|
|
45
|
-
"@ttoss/ids": "^0.2.
|
|
45
|
+
"@ttoss/ids": "^0.2.8"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"graphql": "^16.6.0"
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"@types/yargs": "^17.0.32",
|
|
52
52
|
"graphql": "^16.8.1",
|
|
53
53
|
"jest": "^29.7.0",
|
|
54
|
-
"tsup": "^8.
|
|
55
|
-
"@ttoss/config": "^1.32.
|
|
54
|
+
"tsup": "^8.2.4",
|
|
55
|
+
"@ttoss/config": "^1.32.8"
|
|
56
56
|
},
|
|
57
57
|
"keywords": [
|
|
58
58
|
"api",
|