@envelop/persisted-operations 4.4.0 → 4.4.1-alpha-72027859.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/README.md CHANGED
@@ -15,26 +15,26 @@ yarn add @envelop/persisted-operations
15
15
  The most basic implementation can use an in-memory JS `Map` wrapper with a `Store` object:
16
16
 
17
17
  ```ts
18
- import { envelop } from '@envelop/core';
19
- import { usePersistedOperations, InMemoryStore } from '@envelop/persisted-operations';
18
+ import { envelop } from '@envelop/core'
19
+ import { usePersistedOperations, InMemoryStore } from '@envelop/persisted-operations'
20
20
 
21
21
  // You can retrieve the store in any way (e.g. from a remote source) and implement it with a simple Map / Key->Value
22
- const myData = new Map();
23
- myData.set('persisted_1', parse(`query { ... }`));
24
- myData.set('persisted_2', 'query { ... }'));
22
+ const myData = new Map()
23
+ myData.set('persisted_1', parse(`query { ... }`))
24
+ myData.set('persisted_2', 'query { ... }')
25
25
 
26
26
  const store = new InMemoryStore({
27
- initialData: myData,
27
+ initialData: myData
28
28
  })
29
29
 
30
30
  const getEnveloped = envelop({
31
31
  plugins: [
32
32
  // ... other plugins ...
33
33
  usePersistedOperations({
34
- store: myStore,
35
- }),
36
- ],
37
- });
34
+ store: myStore
35
+ })
36
+ ]
37
+ })
38
38
  ```
39
39
 
40
40
  Now, when running operations through your GraphQL server, you can use a key instead of a query language:
@@ -58,25 +58,25 @@ usePersistedOperations({
58
58
  ## Usage Example with built-in JsonFileStore
59
59
 
60
60
  ```ts
61
- import { usePersistedOperations, JsonFileStore } from '@envelop/persisted-operations';
61
+ import { usePersistedOperations, JsonFileStore } from '@envelop/persisted-operations'
62
62
 
63
- const persistedOperationsStore = new JsonFilesStore();
64
- const filePath = resolve(process.cwd(), 'assets/client1PersistedOperations.json');
63
+ const persistedOperationsStore = new JsonFilesStore()
64
+ const filePath = resolve(process.cwd(), 'assets/client1PersistedOperations.json')
65
65
 
66
66
  // sync
67
- persistedOperationsStore.loadFromFileSync(filePath); // load and parse persisted-operations files
67
+ persistedOperationsStore.loadFromFileSync(filePath) // load and parse persisted-operations files
68
68
 
69
69
  // or async
70
- await persistedOperationsStore.loadFromFile(filePath); // load and parse persisted-operations files
70
+ await persistedOperationsStore.loadFromFile(filePath) // load and parse persisted-operations files
71
71
 
72
72
  const getEnveloped = envelop({
73
73
  plugins: [
74
74
  // ... other plugins ...
75
75
  usePersistedOperations({
76
- store: persistedOperationsStore,
77
- }),
78
- ],
79
- });
76
+ store: persistedOperationsStore
77
+ })
78
+ ]
79
+ })
80
80
  ```
81
81
 
82
82
  ## Multiple Stores
@@ -90,17 +90,17 @@ const getEnveloped = envelop({
90
90
  usePersistedOperations({
91
91
  store: context => {
92
92
  if (context.req.headers['user-agent'].includes('Android')) {
93
- return mobileClientsStore;
93
+ return mobileClientsStore
94
94
  }
95
95
 
96
- return defaultStore;
97
- },
98
- }),
99
- ],
100
- });
96
+ return defaultStore
97
+ }
98
+ })
99
+ ]
100
+ })
101
101
 
102
102
  // later, pass the initial context
103
- const proxyFns = getEnveloped({ req });
103
+ const proxyFns = getEnveloped({ req })
104
104
  ```
105
105
 
106
106
  ## Additional options
@@ -116,8 +116,8 @@ The function receives the context and operationId as arguments, so you can use i
116
116
 
117
117
  ```js
118
118
  onMissingMatch: (context, operationId) => {
119
- myEventPool.add(`Missing match for operation "${operationId}" from agent "${context.req.headers['user-agent']}"`);
120
- };
119
+ myEventPool.add(`Missing match for operation "${operationId}" from agent "${context.req.headers['user-agent']}"`)
120
+ }
121
121
  ```
122
122
 
123
123
  ## With Relay
package/cjs/plugin.js CHANGED
@@ -14,11 +14,13 @@ exports.readOperationId = readOperationId;
14
14
  const usePersistedOperations = (rawOptions) => {
15
15
  const options = {
16
16
  ...DEFAULT_OPTIONS,
17
- ...(rawOptions || {}),
17
+ ...rawOptions,
18
18
  };
19
19
  return {
20
20
  onParse({ context, params, extendContext, setParsedDocument }) {
21
- const operationId = options.extractOperationId ? options.extractOperationId(context) : (0, utils_js_1.operationIdFromSource)(params.source);
21
+ const operationId = options.extractOperationId
22
+ ? options.extractOperationId(context)
23
+ : (0, utils_js_1.operationIdFromSource)(params.source);
22
24
  if (!operationId) {
23
25
  if (options.onlyPersisted) {
24
26
  throw new graphql_1.GraphQLError('Must provide operation id');
package/esm/plugin.js CHANGED
@@ -10,11 +10,13 @@ export function readOperationId(context) {
10
10
  export const usePersistedOperations = (rawOptions) => {
11
11
  const options = {
12
12
  ...DEFAULT_OPTIONS,
13
- ...(rawOptions || {}),
13
+ ...rawOptions,
14
14
  };
15
15
  return {
16
16
  onParse({ context, params, extendContext, setParsedDocument }) {
17
- const operationId = options.extractOperationId ? options.extractOperationId(context) : operationIdFromSource(params.source);
17
+ const operationId = options.extractOperationId
18
+ ? options.extractOperationId(context)
19
+ : operationIdFromSource(params.source);
18
20
  if (!operationId) {
19
21
  if (options.onlyPersisted) {
20
22
  throw new GraphQLError('Must provide operation id');
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/persisted-operations",
3
- "version": "4.4.0",
3
+ "version": "4.4.1-alpha-72027859.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "^2.4.0",
6
+ "@envelop/core": "2.4.1-alpha-72027859.0",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "repository": {