@kubun/with-relay 0.17.0 → 0.17.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/lib/index.d.ts CHANGED
@@ -1,10 +1,25 @@
1
1
  import type { GraphQLSource } from '@kubun/protocol';
2
- import { Environment, type INetwork, Store } from 'relay-runtime';
2
+ import { type CacheConfig, Environment, type INetwork, Store } from 'relay-runtime';
3
3
  export type NetworkParams = {
4
4
  source: GraphQLSource;
5
5
  };
6
6
  export type EnvironmentParams = NetworkParams & {
7
7
  store?: Store;
8
8
  };
9
+ /**
10
+ * The connector operation-envelope ids a mutation carries (see
11
+ * `GraphQLOperationParams.operationID`): required on a connector action
12
+ * mutation, the same pair on every retry of one user intent, a new pair for a
13
+ * new intent.
14
+ */
15
+ export type OperationEnvelope = {
16
+ operationID: string;
17
+ deterministicEventID: string;
18
+ };
19
+ /**
20
+ * The Relay `cacheConfig` that carries an operation envelope to the network
21
+ * layer, for a mutation commit (`commitMutation` / `useMutation`).
22
+ */
23
+ export declare function operationEnvelopeCacheConfig(envelope: OperationEnvelope): CacheConfig;
9
24
  export declare function createNetwork(params: NetworkParams): INetwork;
10
25
  export declare function createEnvironment(params: EnvironmentParams): Environment;
package/lib/index.js CHANGED
@@ -1,7 +1,33 @@
1
1
  import { Environment, Network, Observable, RecordSource, Store } from 'relay-runtime';
2
+ /**
3
+ * The Relay `cacheConfig` that carries an operation envelope to the network
4
+ * layer, for a mutation commit (`commitMutation` / `useMutation`).
5
+ */ export function operationEnvelopeCacheConfig(envelope) {
6
+ return {
7
+ metadata: {
8
+ operationID: envelope.operationID,
9
+ deterministicEventID: envelope.deterministicEventID
10
+ }
11
+ };
12
+ }
13
+ // The operation envelope a mutation's `cacheConfig` carries, each id only
14
+ // when it is a string.
15
+ function operationEnvelopeFrom(cacheConfig) {
16
+ const metadata = cacheConfig?.metadata;
17
+ const operationID = metadata?.operationID;
18
+ const deterministicEventID = metadata?.deterministicEventID;
19
+ return {
20
+ ...typeof operationID === 'string' ? {
21
+ operationID
22
+ } : {},
23
+ ...typeof deterministicEventID === 'string' ? {
24
+ deterministicEventID
25
+ } : {}
26
+ };
27
+ }
2
28
  export function createNetwork(params) {
3
29
  const { source } = params;
4
- return Network.create((request, variables)=>{
30
+ return Network.create((request, variables, cacheConfig)=>{
5
31
  const text = request.text;
6
32
  if (text == null) {
7
33
  return Observable.create((sink)=>{
@@ -12,7 +38,10 @@ export function createNetwork(params) {
12
38
  text,
13
39
  variables: variables
14
40
  };
15
- const promise = request.operationKind === 'mutation' ? source.mutate(params) : source.query(params);
41
+ const promise = request.operationKind === 'mutation' ? source.mutate({
42
+ ...params,
43
+ ...operationEnvelopeFrom(cacheConfig)
44
+ }) : source.query(params);
16
45
  return Observable.from(promise);
17
46
  }, (request, variables)=>{
18
47
  const text = request.text;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/with-relay",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "keywords": [],
5
5
  "license": "see LICENSE.md",
6
6
  "sideEffects": false,
@@ -19,14 +19,14 @@
19
19
  },
20
20
  "devDependencies": {
21
21
  "@enkaku/transport": "^0.21.0",
22
- "@kubun/client": "^0.17.0",
23
- "@kubun/engine": "^0.17.0",
22
+ "@kubun/client": "^0.17.2",
23
+ "@kubun/engine": "^0.17.2",
24
24
  "@kubun/models": "^0.17.0",
25
- "@kubun/plugin-service-server": "^0.17.0",
26
- "@kubun/protocol": "^0.17.0",
27
- "@kubun/service-graph-api": "^0.17.0",
25
+ "@kubun/plugin-service-server": "^0.17.1",
26
+ "@kubun/protocol": "^0.17.1",
27
+ "@kubun/service-graph-api": "^0.17.2",
28
28
  "@kubun/test-utils": "^0.0.0",
29
- "graphql": "^16.14.2"
29
+ "graphql": "^17.0.2"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"