@wishknish/knishio-client-ts 0.8.0 → 0.8.2
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/dist/index.cjs +11 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.iife.js +11 -8
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/KnishIOClient.ts +20 -5
- package/src/libraries/GraphQLClient.ts +7 -4
- package/src/query/QueryActiveSession.ts +1 -0
- package/src/types/index.ts +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wishknish/knishio-client-ts",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"productName": "Knish.IO TypeScript SDK Client",
|
|
5
5
|
"description": "TypeScript implementation of the Knish.IO SDK to consume Knish.IO GraphQL APIs with enhanced type safety.",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
package/src/KnishIOClient.ts
CHANGED
|
@@ -568,7 +568,11 @@ export default class KnishIOClient {
|
|
|
568
568
|
/**
|
|
569
569
|
* Executes a query or mutation
|
|
570
570
|
*/
|
|
571
|
-
async executeQuery(
|
|
571
|
+
async executeQuery(
|
|
572
|
+
query: Query | Mutation,
|
|
573
|
+
variables: Record<string, any> | null = null,
|
|
574
|
+
context: Record<string, any> = {}
|
|
575
|
+
): Promise<Response | null> {
|
|
572
576
|
// Check and refresh authorization token if needed
|
|
573
577
|
// Guard with $__authInProcess to prevent recursive auth refresh
|
|
574
578
|
if (this.$__authToken && this.$__authToken.isExpired() && !this.$__authInProcess) {
|
|
@@ -581,6 +585,8 @@ export default class KnishIOClient {
|
|
|
581
585
|
}
|
|
582
586
|
|
|
583
587
|
if (query instanceof MutationProposeMolecule) {
|
|
588
|
+
// Molecule submissions are writes — never cached, so no request-policy
|
|
589
|
+
// context applies; MutationProposeMolecule.execute takes only variables.
|
|
584
590
|
return await this.withMoleculeLock(async () => {
|
|
585
591
|
const response = await query.execute({ variables: variables || {} })
|
|
586
592
|
this.handlePositionDrift(response)
|
|
@@ -588,8 +594,9 @@ export default class KnishIOClient {
|
|
|
588
594
|
})
|
|
589
595
|
}
|
|
590
596
|
|
|
591
|
-
// Execute the query
|
|
592
|
-
|
|
597
|
+
// Execute the query/mutation, forwarding any urql context (e.g.
|
|
598
|
+
// requestPolicy) assembled by the caller (queryMeta) / createQueryContext().
|
|
599
|
+
return await query.execute({ variables: variables || {}, context })
|
|
593
600
|
}
|
|
594
601
|
|
|
595
602
|
/**
|
|
@@ -1038,7 +1045,8 @@ export default class KnishIOClient {
|
|
|
1038
1045
|
throughMolecule = false,
|
|
1039
1046
|
values = null,
|
|
1040
1047
|
keys = null,
|
|
1041
|
-
atomValues = null
|
|
1048
|
+
atomValues = null,
|
|
1049
|
+
requestPolicy = null
|
|
1042
1050
|
}: {
|
|
1043
1051
|
metaType: MetaType | string
|
|
1044
1052
|
metaId?: MetaId | string | null
|
|
@@ -1055,6 +1063,12 @@ export default class KnishIOClient {
|
|
|
1055
1063
|
values?: any[] | null
|
|
1056
1064
|
keys?: string[] | null
|
|
1057
1065
|
atomValues?: any[] | null
|
|
1066
|
+
/**
|
|
1067
|
+
* urql request policy for this read. Pass 'network-only' to bypass the
|
|
1068
|
+
* client's in-memory cache (e.g. sync engines that must see the current
|
|
1069
|
+
* ledger state). Default null = urql's default (cache-first).
|
|
1070
|
+
*/
|
|
1071
|
+
requestPolicy?: 'cache-first' | 'cache-only' | 'network-only' | 'cache-and-network' | null
|
|
1058
1072
|
}): Promise<Response> {
|
|
1059
1073
|
this.log('info', `KnishIOClient::queryMeta() - Querying metaType: ${metaType}, metaId: ${metaId}...`)
|
|
1060
1074
|
|
|
@@ -1109,7 +1123,8 @@ export default class KnishIOClient {
|
|
|
1109
1123
|
})
|
|
1110
1124
|
}
|
|
1111
1125
|
|
|
1112
|
-
|
|
1126
|
+
const context = requestPolicy ? { requestPolicy } : {}
|
|
1127
|
+
return this.executeQuery(query, variables, context) as Promise<Response>
|
|
1113
1128
|
}
|
|
1114
1129
|
|
|
1115
1130
|
/**
|
|
@@ -159,18 +159,21 @@ export default class GraphQLClient implements IGraphQLClient {
|
|
|
159
159
|
async query<TResult = unknown>(
|
|
160
160
|
request: GraphQLRequest
|
|
161
161
|
): Promise<GraphQLResponse<TResult>> {
|
|
162
|
-
const { query, variables } = request
|
|
163
|
-
|
|
162
|
+
const { query, variables, context } = request
|
|
163
|
+
// Forward the urql context (e.g. requestPolicy: 'network-only'). Without
|
|
164
|
+
// this 3rd arg urql ignores requestPolicy and defaults to cache-first,
|
|
165
|
+
// serving stale results from a long-lived client's in-memory cache.
|
|
166
|
+
const result = await this.$__client.query(query, variables || {}, context).toPromise()
|
|
164
167
|
return this.formatResponse<TResult>(result)
|
|
165
168
|
}
|
|
166
169
|
|
|
167
170
|
async mutation<TResult = unknown>(
|
|
168
171
|
request: GraphQLRequest
|
|
169
172
|
): Promise<GraphQLResponse<TResult>> {
|
|
170
|
-
const { query, variables } = request
|
|
173
|
+
const { query, variables, context } = request
|
|
171
174
|
// Support both query and mutation properties for backward compatibility
|
|
172
175
|
const mutationString = (request as any).mutation || query
|
|
173
|
-
const result = await this.$__client.mutation(mutationString, variables || {}).toPromise()
|
|
176
|
+
const result = await this.$__client.mutation(mutationString, variables || {}, context).toPromise()
|
|
174
177
|
return this.formatResponse<TResult>(result)
|
|
175
178
|
}
|
|
176
179
|
|
package/src/types/index.ts
CHANGED
|
@@ -375,6 +375,13 @@ export interface GraphQLRequest {
|
|
|
375
375
|
query: string
|
|
376
376
|
variables?: Record<string, unknown>
|
|
377
377
|
operationName?: string | null
|
|
378
|
+
/**
|
|
379
|
+
* Per-operation urql context (e.g. `{ requestPolicy: 'network-only' }`).
|
|
380
|
+
* Built by Query.execute() from createQueryContext() + per-call context and
|
|
381
|
+
* MUST be forwarded to the urql client, or requestPolicy is silently ignored
|
|
382
|
+
* and urql falls back to its default cache-first policy.
|
|
383
|
+
*/
|
|
384
|
+
context?: Record<string, unknown>
|
|
378
385
|
}
|
|
379
386
|
|
|
380
387
|
export interface GraphQLResponse<T = unknown> {
|