@ttoss/graphql-api 0.8.3 → 0.8.4
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 +23 -37
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ pnpm add @ttoss/graphql-api graphql
|
|
|
25
25
|
|
|
26
26
|
## Usage
|
|
27
27
|
|
|
28
|
-
This library uses [`graphql-compose`](https://graphql-compose.github.io/) to create the GraphQL schema. It re-
|
|
28
|
+
This library uses [`graphql-compose`](https://graphql-compose.github.io/) to create the GraphQL schema. It re-exports all the [`graphql-compose`](https://graphql-compose.github.io/) types and methods, so you can use it directly from this package.
|
|
29
29
|
|
|
30
30
|
### Type Creation
|
|
31
31
|
|
|
@@ -43,7 +43,7 @@ const UserTC = schemaComposer.createObjectTC({
|
|
|
43
43
|
});
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
This library uses the `tsconfig.json` file from the target package it is being applied on. If you are using relative imports in your package you can skip this section, but, if you use path aliases in your typescript code by leveraging the [`paths`](https://www.typescriptlang.org/tsconfig#paths) property, the [`baseUrl`](https://www.typescriptlang.org/tsconfig#baseUrl) must be filled accordingly.This is needed because in order to interpret the path aliases, `ts-node` uses [`tsconfig-paths`](https://github.com/dividab/tsconfig-paths) to resolve the modules that uses this config, and `tsconfig-paths` needs both `baseUrl` and `paths` values to be non-null. A `tsconfig.json` example that follows such recommendations is given below:
|
|
46
|
+
This library uses the `tsconfig.json` file from the target package it is being applied on. If you are using relative imports in your package you can skip this section, but, if you use path aliases in your typescript code by leveraging the [`paths`](https://www.typescriptlang.org/tsconfig#paths) property, the [`baseUrl`](https://www.typescriptlang.org/tsconfig#baseUrl) must be filled accordingly. This is needed because in order to interpret the path aliases, `ts-node` uses [`tsconfig-paths`](https://github.com/dividab/tsconfig-paths) to resolve the modules that uses this config, and `tsconfig-paths` needs both `baseUrl` and `paths` values to be non-null. A `tsconfig.json` example that follows such recommendations is given below:
|
|
47
47
|
|
|
48
48
|
```json
|
|
49
49
|
{
|
|
@@ -58,7 +58,23 @@ This library uses the `tsconfig.json` file from the target package it is being a
|
|
|
58
58
|
|
|
59
59
|
### Resolvers
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
#### Creating Resolvers
|
|
62
|
+
|
|
63
|
+
Resolvers are functions that resolve a value for a type or field in your schema. Here’s a simple example of how to create a resolver for the `User` type:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
UserTC.addResolver({
|
|
67
|
+
name: 'findById',
|
|
68
|
+
type: UserTC,
|
|
69
|
+
args: {
|
|
70
|
+
id: 'String!',
|
|
71
|
+
},
|
|
72
|
+
resolve: async ({ args }) => {
|
|
73
|
+
// Implement your logic to find a user by ID
|
|
74
|
+
return await findUserById(args.id);
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
```
|
|
62
78
|
|
|
63
79
|
### Integrate All Modules
|
|
64
80
|
|
|
@@ -171,7 +187,7 @@ _We inspired ourselves on [graphql-compose-relay](https://graphql-compose.github
|
|
|
171
187
|
|
|
172
188
|
### Connections
|
|
173
189
|
|
|
174
|
-
This
|
|
190
|
+
This package provides the method `composeWithConnection` to create a connection type and queries for a given type, based on [graphql-compose-connection](https://graphql-compose.github.io/docs/plugins/plugin-connection.html) plugin and following the [Relay Connection Specification](https://facebook.github.io/relay/graphql/connections.htm).
|
|
175
191
|
|
|
176
192
|
```typescript
|
|
177
193
|
import { composeWithConnection } from '@ttoss/graphql-api';
|
|
@@ -276,40 +292,10 @@ The resolver that will be used to find the nodes. It receives the following argu
|
|
|
276
292
|
name: 'String',
|
|
277
293
|
book: 'String',
|
|
278
294
|
},
|
|
295
|
+
// other args
|
|
279
296
|
},
|
|
280
|
-
resolve: async ({
|
|
281
|
-
|
|
282
|
-
}: {
|
|
283
|
-
args: {
|
|
284
|
-
first?: number;
|
|
285
|
-
after?: string;
|
|
286
|
-
last?: number;
|
|
287
|
-
before?: string;
|
|
288
|
-
/**
|
|
289
|
-
* It's the `first` or `last` argument plus one.
|
|
290
|
-
*/
|
|
291
|
-
limit: number;
|
|
292
|
-
/**
|
|
293
|
-
* The `filter` argument, if provided on the query.
|
|
294
|
-
*/
|
|
295
|
-
filter?: {
|
|
296
|
-
name: string;
|
|
297
|
-
book: string;
|
|
298
|
-
};
|
|
299
|
-
/**
|
|
300
|
-
* The `sort` argument, if provided on the query as
|
|
301
|
-
* they keys of the `sort` object. In our example
|
|
302
|
-
* above, it's `ASC` and `DESC`. `scanIndexForward`
|
|
303
|
-
* is the value of the `value` property on the sort
|
|
304
|
-
* object. In our example above, it's `true` for
|
|
305
|
-
* `ASC` and `false` for `DESC`.
|
|
306
|
-
*/
|
|
307
|
-
sort: {
|
|
308
|
-
scanIndexForward: boolean;
|
|
309
|
-
};
|
|
310
|
-
};
|
|
311
|
-
}) => {
|
|
312
|
-
//
|
|
297
|
+
resolve: async ({ args }) => {
|
|
298
|
+
// find many
|
|
313
299
|
},
|
|
314
300
|
});
|
|
315
301
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/graphql-api",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4",
|
|
4
4
|
"description": "A library for building GraphQL APIs using ttoss ecosystem.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ttoss",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"graphql-middleware": "^6.1.35",
|
|
36
36
|
"graphql-shield": "^7.6.5",
|
|
37
37
|
"npmlog": "^7.0.1",
|
|
38
|
-
"@ttoss/ids": "^0.3.
|
|
38
|
+
"@ttoss/ids": "^0.3.3"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"graphql": "^16.6.0"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"graphql": "^16.9.0",
|
|
45
45
|
"jest": "^29.7.0",
|
|
46
46
|
"tsup": "^8.3.5",
|
|
47
|
-
"@ttoss/config": "^1.35.
|
|
47
|
+
"@ttoss/config": "^1.35.3"
|
|
48
48
|
},
|
|
49
49
|
"keywords": [
|
|
50
50
|
"api",
|