@stonecrop/graphql-client 0.9.0 → 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.
Files changed (2) hide show
  1. package/README.md +80 -1
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,2 +1,81 @@
1
- # Stonecrop GraphQL
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stonecrop/graphql-client",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": {
@@ -33,8 +33,8 @@
33
33
  "decimal.js": "^10.6.0",
34
34
  "graphql": "^16.12.0",
35
35
  "graphql-request": "^7.4.0",
36
- "@stonecrop/schema": "0.9.0",
37
- "@stonecrop/stonecrop": "0.9.0"
36
+ "@stonecrop/schema": "0.9.1",
37
+ "@stonecrop/stonecrop": "0.9.1"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@eslint/js": "^9.39.2",