@stonecrop/graphql-client 0.8.13 → 0.9.1
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
CHANGED
|
@@ -1,2 +1,81 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @stonecrop/graphql-client
|
|
2
2
|
|
|
3
|
+
Client-side TypeScript interface to the Stonecrop GraphQL API. `StonecropClient` wraps the `stonecrop*` operations added to a PostGraphile schema by `@stonecrop/graphql-middleware`, handling HTTP transport, response unwrapping, and metadata caching so application code works with plain TypeScript objects rather than raw GraphQL.
|
|
4
|
+
|
|
5
|
+
The client is intentionally thin — it has no knowledge of doctype definitions itself and fetches metadata from the server on demand, caching it in memory for the lifetime of the instance.
|
|
6
|
+
|
|
7
|
+
While designed to pair with `@stonecrop/graphql-middleware`, the client works against any GraphQL endpoint that implements the `stonecrop*` operation conventions (`stonecropMeta`, `stonecropRecord`, `stonecropRecords`, `stonecropAction`). You can use your own server implementation as long as it conforms to those operation names and the expected response shapes. The `query` and `mutate` methods are also available for interacting with any other operations your schema exposes.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @stonecrop/graphql-client
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { StonecropClient } from '@stonecrop/graphql-client'
|
|
19
|
+
|
|
20
|
+
const client = new StonecropClient({
|
|
21
|
+
endpoint: 'http://localhost:4000/graphql',
|
|
22
|
+
headers: { Authorization: `Bearer ${token}` }, // optional
|
|
23
|
+
})
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Metadata
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
// Fetch DoctypeMeta for a single doctype (cached after first call)
|
|
30
|
+
const meta = await client.getMeta({ doctype: 'SalesOrder' })
|
|
31
|
+
|
|
32
|
+
// Fetch all registered doctypes
|
|
33
|
+
const allMeta = await client.getAllMeta()
|
|
34
|
+
|
|
35
|
+
// Bust the in-memory cache
|
|
36
|
+
client.clearMetaCache()
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Reading records
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
// Single record by ID
|
|
43
|
+
const order = await client.getRecord(meta, 'uuid-here')
|
|
44
|
+
// → Record<string, unknown> | null
|
|
45
|
+
|
|
46
|
+
// List with optional filtering and pagination
|
|
47
|
+
const orders = await client.getRecords(meta, {
|
|
48
|
+
filters: { status: 'Draft' },
|
|
49
|
+
orderBy: 'createdAt',
|
|
50
|
+
limit: 20,
|
|
51
|
+
offset: 0,
|
|
52
|
+
})
|
|
53
|
+
// → Record<string, unknown>[]
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Actions
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
// Dispatch any registered action
|
|
60
|
+
const result = await client.runAction(meta, 'submit', ['uuid-here'])
|
|
61
|
+
// → { success: boolean; data: unknown; error: string | null }
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Raw GraphQL
|
|
65
|
+
|
|
66
|
+
For queries or mutations not covered by the helpers:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
const data = await client.query<{ myTable: unknown[] }>(
|
|
70
|
+
`query { myTable { id name } }`
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
const result = await client.mutate<{ createFoo: unknown }>(
|
|
74
|
+
`mutation CreateFoo($input: CreateFooInput!) { createFoo(input: $input) { foo { id } } }`,
|
|
75
|
+
{ input: { foo: { name: 'bar' } } }
|
|
76
|
+
)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## References
|
|
80
|
+
|
|
81
|
+
For full method signatures and parameter details, see [API Reference](./api.md).
|
package/dist/graphql-client.d.ts
CHANGED
|
@@ -1,217 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DoctypeMeta } from '@stonecrop/schema';
|
|
2
|
+
import type { RouteContext } from '@stonecrop/schema';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
* Doctype metadata - complete definition of a doctype
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export declare const DoctypeMeta: z.ZodObject<{
|
|
8
|
-
/** Display name of the doctype */
|
|
9
|
-
name: z.ZodString;
|
|
10
|
-
/** URL-friendly slug (kebab-case) */
|
|
11
|
-
slug: z.ZodOptional<z.ZodString>;
|
|
12
|
-
/** Database table name */
|
|
13
|
-
tableName: z.ZodOptional<z.ZodString>;
|
|
14
|
-
/** Field definitions */
|
|
15
|
-
fields: z.ZodArray<z.ZodObject<{
|
|
16
|
-
fieldname: z.ZodString;
|
|
17
|
-
fieldtype: z.ZodEnum<["Data", "Text", "Int", "Float", "Decimal", "Check", "Date", "Time", "Datetime", "Duration", "DateRange", "JSON", "Code", "Link", "Doctype", "Attach", "Currency", "Quantity", "Select"]>;
|
|
18
|
-
component: z.ZodOptional<z.ZodString>;
|
|
19
|
-
label: z.ZodOptional<z.ZodString>;
|
|
20
|
-
width: z.ZodOptional<z.ZodString>;
|
|
21
|
-
align: z.ZodOptional<z.ZodEnum<["left", "center", "right", "start", "end"]>>;
|
|
22
|
-
required: z.ZodOptional<z.ZodBoolean>;
|
|
23
|
-
readOnly: z.ZodOptional<z.ZodBoolean>;
|
|
24
|
-
edit: z.ZodOptional<z.ZodBoolean>;
|
|
25
|
-
hidden: z.ZodOptional<z.ZodBoolean>;
|
|
26
|
-
value: z.ZodOptional<z.ZodUnknown>;
|
|
27
|
-
default: z.ZodOptional<z.ZodUnknown>;
|
|
28
|
-
options: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
29
|
-
mask: z.ZodOptional<z.ZodString>;
|
|
30
|
-
validation: z.ZodOptional<z.ZodObject<{
|
|
31
|
-
errorMessage: z.ZodString;
|
|
32
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
33
|
-
errorMessage: z.ZodString;
|
|
34
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
35
|
-
errorMessage: z.ZodString;
|
|
36
|
-
}, z.ZodTypeAny, "passthrough">>>;
|
|
37
|
-
}, "strip", z.ZodTypeAny, {
|
|
38
|
-
fieldname: string;
|
|
39
|
-
fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
|
|
40
|
-
value?: unknown;
|
|
41
|
-
options?: string | string[] | Record<string, unknown> | undefined;
|
|
42
|
-
validation?: z.objectOutputType<{
|
|
43
|
-
errorMessage: z.ZodString;
|
|
44
|
-
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
45
|
-
component?: string | undefined;
|
|
46
|
-
label?: string | undefined;
|
|
47
|
-
width?: string | undefined;
|
|
48
|
-
align?: "left" | "center" | "right" | "start" | "end" | undefined;
|
|
49
|
-
required?: boolean | undefined;
|
|
50
|
-
readOnly?: boolean | undefined;
|
|
51
|
-
edit?: boolean | undefined;
|
|
52
|
-
hidden?: boolean | undefined;
|
|
53
|
-
default?: unknown;
|
|
54
|
-
mask?: string | undefined;
|
|
55
|
-
}, {
|
|
56
|
-
fieldname: string;
|
|
57
|
-
fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
|
|
58
|
-
value?: unknown;
|
|
59
|
-
options?: string | string[] | Record<string, unknown> | undefined;
|
|
60
|
-
validation?: z.objectInputType<{
|
|
61
|
-
errorMessage: z.ZodString;
|
|
62
|
-
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
63
|
-
component?: string | undefined;
|
|
64
|
-
label?: string | undefined;
|
|
65
|
-
width?: string | undefined;
|
|
66
|
-
align?: "left" | "center" | "right" | "start" | "end" | undefined;
|
|
67
|
-
required?: boolean | undefined;
|
|
68
|
-
readOnly?: boolean | undefined;
|
|
69
|
-
edit?: boolean | undefined;
|
|
70
|
-
hidden?: boolean | undefined;
|
|
71
|
-
default?: unknown;
|
|
72
|
-
mask?: string | undefined;
|
|
73
|
-
}>, "many">;
|
|
74
|
-
/** Workflow configuration */
|
|
75
|
-
workflow: z.ZodOptional<z.ZodObject<{
|
|
76
|
-
/** List of workflow states */
|
|
77
|
-
states: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
78
|
-
/** Actions available in this workflow */
|
|
79
|
-
actions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
80
|
-
/** Display label for the action */
|
|
81
|
-
label: z.ZodString;
|
|
82
|
-
/** Handler function name or path */
|
|
83
|
-
handler: z.ZodString;
|
|
84
|
-
/** Fields that must have values before action can execute */
|
|
85
|
-
requiredFields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
86
|
-
/** Workflow states where this action is available */
|
|
87
|
-
allowedStates: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
88
|
-
/** Whether to show a confirmation dialog */
|
|
89
|
-
confirm: z.ZodOptional<z.ZodBoolean>;
|
|
90
|
-
/** Additional arguments for the action */
|
|
91
|
-
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
92
|
-
}, "strip", z.ZodTypeAny, {
|
|
93
|
-
label: string;
|
|
94
|
-
handler: string;
|
|
95
|
-
requiredFields?: string[] | undefined;
|
|
96
|
-
allowedStates?: string[] | undefined;
|
|
97
|
-
confirm?: boolean | undefined;
|
|
98
|
-
args?: Record<string, unknown> | undefined;
|
|
99
|
-
}, {
|
|
100
|
-
label: string;
|
|
101
|
-
handler: string;
|
|
102
|
-
requiredFields?: string[] | undefined;
|
|
103
|
-
allowedStates?: string[] | undefined;
|
|
104
|
-
confirm?: boolean | undefined;
|
|
105
|
-
args?: Record<string, unknown> | undefined;
|
|
106
|
-
}>>>;
|
|
107
|
-
}, "strip", z.ZodTypeAny, {
|
|
108
|
-
states?: string[] | undefined;
|
|
109
|
-
actions?: Record<string, {
|
|
110
|
-
label: string;
|
|
111
|
-
handler: string;
|
|
112
|
-
requiredFields?: string[] | undefined;
|
|
113
|
-
allowedStates?: string[] | undefined;
|
|
114
|
-
confirm?: boolean | undefined;
|
|
115
|
-
args?: Record<string, unknown> | undefined;
|
|
116
|
-
}> | undefined;
|
|
117
|
-
}, {
|
|
118
|
-
states?: string[] | undefined;
|
|
119
|
-
actions?: Record<string, {
|
|
120
|
-
label: string;
|
|
121
|
-
handler: string;
|
|
122
|
-
requiredFields?: string[] | undefined;
|
|
123
|
-
allowedStates?: string[] | undefined;
|
|
124
|
-
confirm?: boolean | undefined;
|
|
125
|
-
args?: Record<string, unknown> | undefined;
|
|
126
|
-
}> | undefined;
|
|
127
|
-
}>>;
|
|
128
|
-
/** Parent doctype for inheritance */
|
|
129
|
-
inherits: z.ZodOptional<z.ZodString>;
|
|
130
|
-
/** Doctype to use for list views */
|
|
131
|
-
listDoctype: z.ZodOptional<z.ZodString>;
|
|
132
|
-
/** Parent doctype for child tables */
|
|
133
|
-
parentDoctype: z.ZodOptional<z.ZodString>;
|
|
134
|
-
}, "strip", z.ZodTypeAny, {
|
|
135
|
-
name: string;
|
|
136
|
-
fields: {
|
|
137
|
-
fieldname: string;
|
|
138
|
-
fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
|
|
139
|
-
value?: unknown;
|
|
140
|
-
options?: string | string[] | Record<string, unknown> | undefined;
|
|
141
|
-
validation?: z.objectOutputType<{
|
|
142
|
-
errorMessage: z.ZodString;
|
|
143
|
-
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
144
|
-
component?: string | undefined;
|
|
145
|
-
label?: string | undefined;
|
|
146
|
-
width?: string | undefined;
|
|
147
|
-
align?: "left" | "center" | "right" | "start" | "end" | undefined;
|
|
148
|
-
required?: boolean | undefined;
|
|
149
|
-
readOnly?: boolean | undefined;
|
|
150
|
-
edit?: boolean | undefined;
|
|
151
|
-
hidden?: boolean | undefined;
|
|
152
|
-
default?: unknown;
|
|
153
|
-
mask?: string | undefined;
|
|
154
|
-
}[];
|
|
155
|
-
slug?: string | undefined;
|
|
156
|
-
tableName?: string | undefined;
|
|
157
|
-
workflow?: {
|
|
158
|
-
states?: string[] | undefined;
|
|
159
|
-
actions?: Record<string, {
|
|
160
|
-
label: string;
|
|
161
|
-
handler: string;
|
|
162
|
-
requiredFields?: string[] | undefined;
|
|
163
|
-
allowedStates?: string[] | undefined;
|
|
164
|
-
confirm?: boolean | undefined;
|
|
165
|
-
args?: Record<string, unknown> | undefined;
|
|
166
|
-
}> | undefined;
|
|
167
|
-
} | undefined;
|
|
168
|
-
inherits?: string | undefined;
|
|
169
|
-
listDoctype?: string | undefined;
|
|
170
|
-
parentDoctype?: string | undefined;
|
|
171
|
-
}, {
|
|
172
|
-
name: string;
|
|
173
|
-
fields: {
|
|
174
|
-
fieldname: string;
|
|
175
|
-
fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
|
|
176
|
-
value?: unknown;
|
|
177
|
-
options?: string | string[] | Record<string, unknown> | undefined;
|
|
178
|
-
validation?: z.objectInputType<{
|
|
179
|
-
errorMessage: z.ZodString;
|
|
180
|
-
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
181
|
-
component?: string | undefined;
|
|
182
|
-
label?: string | undefined;
|
|
183
|
-
width?: string | undefined;
|
|
184
|
-
align?: "left" | "center" | "right" | "start" | "end" | undefined;
|
|
185
|
-
required?: boolean | undefined;
|
|
186
|
-
readOnly?: boolean | undefined;
|
|
187
|
-
edit?: boolean | undefined;
|
|
188
|
-
hidden?: boolean | undefined;
|
|
189
|
-
default?: unknown;
|
|
190
|
-
mask?: string | undefined;
|
|
191
|
-
}[];
|
|
192
|
-
slug?: string | undefined;
|
|
193
|
-
tableName?: string | undefined;
|
|
194
|
-
workflow?: {
|
|
195
|
-
states?: string[] | undefined;
|
|
196
|
-
actions?: Record<string, {
|
|
197
|
-
label: string;
|
|
198
|
-
handler: string;
|
|
199
|
-
requiredFields?: string[] | undefined;
|
|
200
|
-
allowedStates?: string[] | undefined;
|
|
201
|
-
confirm?: boolean | undefined;
|
|
202
|
-
args?: Record<string, unknown> | undefined;
|
|
203
|
-
}> | undefined;
|
|
204
|
-
} | undefined;
|
|
205
|
-
inherits?: string | undefined;
|
|
206
|
-
listDoctype?: string | undefined;
|
|
207
|
-
parentDoctype?: string | undefined;
|
|
208
|
-
}>;
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Doctype metadata type inferred from Zod schema
|
|
212
|
-
* @public
|
|
213
|
-
*/
|
|
214
|
-
export declare type DoctypeMeta = z.infer<typeof DoctypeMeta>;
|
|
4
|
+
export { DoctypeMeta }
|
|
215
5
|
|
|
216
6
|
/**
|
|
217
7
|
* @file This file contains all the types that are used in the application.
|
|
@@ -279,19 +69,7 @@ export declare const queries: {
|
|
|
279
69
|
getMeta: string;
|
|
280
70
|
};
|
|
281
71
|
|
|
282
|
-
|
|
283
|
-
* Route context for identifying what doctype/record we're working with.
|
|
284
|
-
* Used by graphql-middleware and graphql-client to resolve schema metadata.
|
|
285
|
-
* @public
|
|
286
|
-
*/
|
|
287
|
-
export declare interface RouteContext {
|
|
288
|
-
/** Doctype name (e.g., 'Task', 'Customer') */
|
|
289
|
-
doctype: string;
|
|
290
|
-
/** Optional record ID for viewing/editing a specific record */
|
|
291
|
-
recordId?: string;
|
|
292
|
-
/** Additional context properties */
|
|
293
|
-
[key: string]: unknown;
|
|
294
|
-
}
|
|
72
|
+
export { RouteContext }
|
|
295
73
|
|
|
296
74
|
/**
|
|
297
75
|
* Client for interacting with Stonecrop GraphQL API
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/graphql-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": {
|
|
@@ -15,30 +15,26 @@
|
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/agritheory/stonecrop/issues"
|
|
17
17
|
},
|
|
18
|
+
"description": "GraphQL client integration for Stonecrop",
|
|
19
|
+
"types": "./dist/graphql-client.d.ts",
|
|
18
20
|
"exports": {
|
|
19
21
|
".": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
"default": "./dist/graphql-client.js"
|
|
23
|
-
},
|
|
24
|
-
"require": "./dist/graphql-client.umd.cjs"
|
|
22
|
+
"types": "./dist/graphql-client.d.ts",
|
|
23
|
+
"import": "./dist/graphql-client.js"
|
|
25
24
|
},
|
|
26
|
-
"./types":
|
|
27
|
-
"import": "./dist/src/types/index.d.ts",
|
|
28
|
-
"require": "./dist/src/types/index.d.ts"
|
|
29
|
-
}
|
|
25
|
+
"./types": "./dist/src/types/index.d.ts"
|
|
30
26
|
},
|
|
31
|
-
"typings": "./dist/src/index.d.ts",
|
|
32
27
|
"files": [
|
|
33
28
|
"dist/*",
|
|
34
29
|
"src/*"
|
|
35
30
|
],
|
|
31
|
+
"sideEffects": false,
|
|
36
32
|
"dependencies": {
|
|
37
33
|
"decimal.js": "^10.6.0",
|
|
38
34
|
"graphql": "^16.12.0",
|
|
39
35
|
"graphql-request": "^7.4.0",
|
|
40
|
-
"@stonecrop/schema": "0.
|
|
41
|
-
"@stonecrop/stonecrop": "0.
|
|
36
|
+
"@stonecrop/schema": "0.9.1",
|
|
37
|
+
"@stonecrop/stonecrop": "0.9.1"
|
|
42
38
|
},
|
|
43
39
|
"devDependencies": {
|
|
44
40
|
"@eslint/js": "^9.39.2",
|
|
@@ -68,7 +64,6 @@
|
|
|
68
64
|
},
|
|
69
65
|
"scripts": {
|
|
70
66
|
"_phase:build": "heft build && vite build && rushx docs",
|
|
71
|
-
"prepublish": "heft build && vite build && rushx docs",
|
|
72
67
|
"build": "heft build && vite build && rushx docs",
|
|
73
68
|
"dev": "vite",
|
|
74
69
|
"docs": "bash ../common/scripts/run-docs.sh graphql_client",
|