@ttoss/graphql-api 0.9.11 → 0.10.0
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 +34 -0
- package/dist/index.d.cts +32 -1
- package/dist/index.d.ts +32 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -549,6 +549,40 @@ The resolver `connection` has the following arguments based on the [Relay Connec
|
|
|
549
549
|
});
|
|
550
550
|
```
|
|
551
551
|
|
|
552
|
+
#### `ConnectionArgs` type
|
|
553
|
+
|
|
554
|
+
To type a connection resolver in TypeScript, import the generic `ConnectionArgs<TFilter, TSort>` helper. It captures all of the standard pagination arguments (`first`, `after`, `last`, `before`, `limit`, `skip`, `sort`, `filter`) and lets you specify only the connection-specific parts:
|
|
555
|
+
|
|
556
|
+
```ts
|
|
557
|
+
import {
|
|
558
|
+
type ConnectionArgs,
|
|
559
|
+
type ResolverResolveParams,
|
|
560
|
+
} from '@ttoss/graphql-api';
|
|
561
|
+
|
|
562
|
+
type NotificationFilter = {
|
|
563
|
+
isRead?: boolean | null;
|
|
564
|
+
kind?: string | null;
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
NotificationTC.addResolver({
|
|
568
|
+
name: 'findMany',
|
|
569
|
+
type: [NotificationTC.NonNull],
|
|
570
|
+
resolve: async ({
|
|
571
|
+
args,
|
|
572
|
+
}: ResolverResolveParams<
|
|
573
|
+
unknown,
|
|
574
|
+
ResolverContext,
|
|
575
|
+
ConnectionArgs<NotificationFilter>
|
|
576
|
+
>) => {
|
|
577
|
+
return findManyNotifications({
|
|
578
|
+
first: args.first,
|
|
579
|
+
after: args.after,
|
|
580
|
+
filter: args.filter,
|
|
581
|
+
});
|
|
582
|
+
},
|
|
583
|
+
});
|
|
584
|
+
```
|
|
585
|
+
|
|
552
586
|
To configure `composeWithConnection`, you need to provide the following options:
|
|
553
587
|
|
|
554
588
|
#### `findManyResolver`
|
package/dist/index.d.cts
CHANGED
|
@@ -13,4 +13,35 @@ declare const buildSchema: ({ schemaComposer, middlewares, }: BuildSchemaInput)
|
|
|
13
13
|
|
|
14
14
|
declare const composeWithRelay: <TContext>(tc: ObjectTypeComposer<any, TContext>) => ObjectTypeComposer<any, TContext>;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Standard connection arguments used by resolvers created with `composeWithConnection`.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam TFilter - Shape of the connection-specific filter object. Defaults to `unknown`.
|
|
20
|
+
* @typeParam TSort - Shape of the sort value. Defaults to `unknown`.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { type ConnectionArgs, type ResolverResolveParams } from '@ttoss/graphql-api';
|
|
25
|
+
*
|
|
26
|
+
* type NotificationFilter = { isRead?: boolean | null };
|
|
27
|
+
*
|
|
28
|
+
* NotificationTC.addResolver({
|
|
29
|
+
* name: 'findMany',
|
|
30
|
+
* resolve: async ({ args }: ResolverResolveParams<unknown, Context, ConnectionArgs<NotificationFilter>>) => {
|
|
31
|
+
* return findMany({ first: args.first, after: args.after, filter: args.filter });
|
|
32
|
+
* },
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
type ConnectionArgs<TFilter = unknown, TSort = unknown> = {
|
|
37
|
+
first?: number | null;
|
|
38
|
+
after?: string | null;
|
|
39
|
+
last?: number | null;
|
|
40
|
+
before?: string | null;
|
|
41
|
+
limit?: number | null;
|
|
42
|
+
skip?: number | null;
|
|
43
|
+
sort?: TSort;
|
|
44
|
+
filter?: TFilter | null;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { type BuildSchemaInput, type ConnectionArgs, buildSchema, composeWithRelay };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,4 +13,35 @@ declare const buildSchema: ({ schemaComposer, middlewares, }: BuildSchemaInput)
|
|
|
13
13
|
|
|
14
14
|
declare const composeWithRelay: <TContext>(tc: ObjectTypeComposer<any, TContext>) => ObjectTypeComposer<any, TContext>;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Standard connection arguments used by resolvers created with `composeWithConnection`.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam TFilter - Shape of the connection-specific filter object. Defaults to `unknown`.
|
|
20
|
+
* @typeParam TSort - Shape of the sort value. Defaults to `unknown`.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { type ConnectionArgs, type ResolverResolveParams } from '@ttoss/graphql-api';
|
|
25
|
+
*
|
|
26
|
+
* type NotificationFilter = { isRead?: boolean | null };
|
|
27
|
+
*
|
|
28
|
+
* NotificationTC.addResolver({
|
|
29
|
+
* name: 'findMany',
|
|
30
|
+
* resolve: async ({ args }: ResolverResolveParams<unknown, Context, ConnectionArgs<NotificationFilter>>) => {
|
|
31
|
+
* return findMany({ first: args.first, after: args.after, filter: args.filter });
|
|
32
|
+
* },
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
type ConnectionArgs<TFilter = unknown, TSort = unknown> = {
|
|
37
|
+
first?: number | null;
|
|
38
|
+
after?: string | null;
|
|
39
|
+
last?: number | null;
|
|
40
|
+
before?: string | null;
|
|
41
|
+
limit?: number | null;
|
|
42
|
+
skip?: number | null;
|
|
43
|
+
sort?: TSort;
|
|
44
|
+
filter?: TFilter | null;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { type BuildSchemaInput, type ConnectionArgs, buildSchema, composeWithRelay };
|