@svadmin/graphql 0.8.0 → 0.9.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/package.json +1 -1
- package/src/data-provider.ts +8 -8
package/package.json
CHANGED
package/src/data-provider.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
DataProvider, GetListParams, GetListResult, GetOneParams, GetOneResult,
|
|
3
3
|
CreateParams, CreateResult, UpdateParams, UpdateResult, DeleteParams, DeleteResult,
|
|
4
|
-
CustomParams, CustomResult,
|
|
4
|
+
CustomParams, CustomResult, BaseRecord
|
|
5
5
|
} from '@svadmin/core';
|
|
6
6
|
import type { GraphQLClient, RequestDocument, Variables } from 'graphql-request';
|
|
7
7
|
|
|
@@ -30,7 +30,7 @@ export function createGraphQLDataProvider(options: GraphQLDataProviderOptions):
|
|
|
30
30
|
return {
|
|
31
31
|
getApiUrl: () => 'graphql',
|
|
32
32
|
|
|
33
|
-
async getList<T>({ resource, pagination, meta }: GetListParams): Promise<GetListResult<T>> {
|
|
33
|
+
async getList<T extends BaseRecord = BaseRecord>({ resource, pagination, meta }: GetListParams): Promise<GetListResult<T>> {
|
|
34
34
|
const query = getQuery(meta, 'getList', resource);
|
|
35
35
|
const variables: Variables = {
|
|
36
36
|
...getMetaVars(meta),
|
|
@@ -42,40 +42,40 @@ export function createGraphQLDataProvider(options: GraphQLDataProviderOptions):
|
|
|
42
42
|
|
|
43
43
|
const response = await client.request<{ data: T[]; total?: number }>(query, variables);
|
|
44
44
|
return {
|
|
45
|
-
data: response.data || ([] as T[]),
|
|
45
|
+
data: response.data || ([] as unknown as T[]),
|
|
46
46
|
total: response.total || 0,
|
|
47
47
|
};
|
|
48
48
|
},
|
|
49
49
|
|
|
50
|
-
async getOne<T>({ resource, id, meta }: GetOneParams): Promise<GetOneResult<T>> {
|
|
50
|
+
async getOne<T extends BaseRecord = BaseRecord>({ resource, id, meta }: GetOneParams): Promise<GetOneResult<T>> {
|
|
51
51
|
const query = getQuery(meta, 'getOne', resource);
|
|
52
52
|
const variables: Variables = { id, ...getMetaVars(meta) };
|
|
53
53
|
const response = await client.request<{ data: T }>(query, variables);
|
|
54
54
|
return { data: response.data };
|
|
55
55
|
},
|
|
56
56
|
|
|
57
|
-
async create<T>({ resource, variables, meta }: CreateParams): Promise<CreateResult<T>> {
|
|
57
|
+
async create<T extends BaseRecord = BaseRecord>({ resource, variables, meta }: CreateParams): Promise<CreateResult<T>> {
|
|
58
58
|
const query = getQuery(meta, 'create', resource);
|
|
59
59
|
const allVars: Variables = { ...(variables as Record<string, unknown>), ...getMetaVars(meta) };
|
|
60
60
|
const response = await client.request<{ data: T }>(query, allVars);
|
|
61
61
|
return { data: response.data };
|
|
62
62
|
},
|
|
63
63
|
|
|
64
|
-
async update<T>({ resource, id, variables, meta }: UpdateParams): Promise<UpdateResult<T>> {
|
|
64
|
+
async update<T extends BaseRecord = BaseRecord>({ resource, id, variables, meta }: UpdateParams): Promise<UpdateResult<T>> {
|
|
65
65
|
const query = getQuery(meta, 'update', resource);
|
|
66
66
|
const allVars: Variables = { id, ...(variables as Record<string, unknown>), ...getMetaVars(meta) };
|
|
67
67
|
const response = await client.request<{ data: T }>(query, allVars);
|
|
68
68
|
return { data: response.data };
|
|
69
69
|
},
|
|
70
70
|
|
|
71
|
-
async deleteOne<T>({ resource, id, meta }: DeleteParams): Promise<DeleteResult<T>> {
|
|
71
|
+
async deleteOne<T extends BaseRecord = BaseRecord>({ resource, id, meta }: DeleteParams): Promise<DeleteResult<T>> {
|
|
72
72
|
const query = getQuery(meta, 'deleteOne', resource);
|
|
73
73
|
const allVars: Variables = { id, ...getMetaVars(meta) };
|
|
74
74
|
const response = await client.request<{ data: T }>(query, allVars);
|
|
75
75
|
return { data: response.data };
|
|
76
76
|
},
|
|
77
77
|
|
|
78
|
-
async custom<T>({ meta, payload, headers }: CustomParams): Promise<CustomResult<T>> {
|
|
78
|
+
async custom<T = unknown>({ meta, payload, headers }: CustomParams): Promise<CustomResult<T>> {
|
|
79
79
|
if (!meta?.query) {
|
|
80
80
|
throw new Error(`[svadmin/graphql] custom requires 'meta.query'`);
|
|
81
81
|
}
|