@graphql-mesh/plugin-mock 1.0.0-alpha-20230523154127-518d8667d → 1.0.0-alpha-20230523154231-8c60b52d9
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/cjs/index.js +5 -4
- package/esm/index.js +5 -4
- package/package.json +8 -11
package/cjs/index.js
CHANGED
|
@@ -14,6 +14,7 @@ function useMock(config) {
|
|
|
14
14
|
if (configIf) {
|
|
15
15
|
return {
|
|
16
16
|
onSchemaChange({ schema, replaceSchema }) {
|
|
17
|
+
var _a;
|
|
17
18
|
if (mockedSchemas.has(schema)) {
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
@@ -25,11 +26,11 @@ function useMock(config) {
|
|
|
25
26
|
for (const typeName in typeMap) {
|
|
26
27
|
const type = typeMap[typeName];
|
|
27
28
|
const examples = type.extensions.examples;
|
|
28
|
-
if (examples
|
|
29
|
+
if (examples === null || examples === void 0 ? void 0 : examples.length) {
|
|
29
30
|
mocks[typeName] = () => examples[Math.floor(Math.random() * examples.length)];
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
|
-
if (config
|
|
33
|
+
if ((_a = config === null || config === void 0 ? void 0 : config.mocks) === null || _a === void 0 ? void 0 : _a.length) {
|
|
33
34
|
for (const fieldConfig of config.mocks) {
|
|
34
35
|
const fieldConfigIf = 'if' in fieldConfig ? fieldConfig.if : true;
|
|
35
36
|
if (fieldConfigIf) {
|
|
@@ -128,7 +129,7 @@ function useMock(config) {
|
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
131
|
const store = (0, mock_1.createMockStore)({ schema, mocks });
|
|
131
|
-
if (config
|
|
132
|
+
if (config === null || config === void 0 ? void 0 : config.initializeStore) {
|
|
132
133
|
const initializeStoreFn$ = (0, utils_1.loadFromModuleExportExpression)(config.initializeStore, {
|
|
133
134
|
cwd: config.baseDir,
|
|
134
135
|
defaultExportName: 'default',
|
|
@@ -142,7 +143,7 @@ function useMock(config) {
|
|
|
142
143
|
store,
|
|
143
144
|
mocks,
|
|
144
145
|
resolvers,
|
|
145
|
-
preserveResolvers: config
|
|
146
|
+
preserveResolvers: config === null || config === void 0 ? void 0 : config.preserveResolvers,
|
|
146
147
|
});
|
|
147
148
|
mockedSchemas.add(mockedSchema);
|
|
148
149
|
replaceSchema(mockedSchema);
|
package/esm/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export default function useMock(config) {
|
|
|
11
11
|
if (configIf) {
|
|
12
12
|
return {
|
|
13
13
|
onSchemaChange({ schema, replaceSchema }) {
|
|
14
|
+
var _a;
|
|
14
15
|
if (mockedSchemas.has(schema)) {
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
@@ -22,11 +23,11 @@ export default function useMock(config) {
|
|
|
22
23
|
for (const typeName in typeMap) {
|
|
23
24
|
const type = typeMap[typeName];
|
|
24
25
|
const examples = type.extensions.examples;
|
|
25
|
-
if (examples
|
|
26
|
+
if (examples === null || examples === void 0 ? void 0 : examples.length) {
|
|
26
27
|
mocks[typeName] = () => examples[Math.floor(Math.random() * examples.length)];
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
|
-
if (config
|
|
30
|
+
if ((_a = config === null || config === void 0 ? void 0 : config.mocks) === null || _a === void 0 ? void 0 : _a.length) {
|
|
30
31
|
for (const fieldConfig of config.mocks) {
|
|
31
32
|
const fieldConfigIf = 'if' in fieldConfig ? fieldConfig.if : true;
|
|
32
33
|
if (fieldConfigIf) {
|
|
@@ -125,7 +126,7 @@ export default function useMock(config) {
|
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
const store = createMockStore({ schema, mocks });
|
|
128
|
-
if (config
|
|
129
|
+
if (config === null || config === void 0 ? void 0 : config.initializeStore) {
|
|
129
130
|
const initializeStoreFn$ = loadFromModuleExportExpression(config.initializeStore, {
|
|
130
131
|
cwd: config.baseDir,
|
|
131
132
|
defaultExportName: 'default',
|
|
@@ -139,7 +140,7 @@ export default function useMock(config) {
|
|
|
139
140
|
store,
|
|
140
141
|
mocks,
|
|
141
142
|
resolvers,
|
|
142
|
-
preserveResolvers: config
|
|
143
|
+
preserveResolvers: config === null || config === void 0 ? void 0 : config.preserveResolvers,
|
|
143
144
|
});
|
|
144
145
|
mockedSchemas.add(mockedSchema);
|
|
145
146
|
replaceSchema(mockedSchema);
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/plugin-mock",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230523154231-8c60b52d9",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/cross-helpers": "0.4.0-alpha-
|
|
7
|
-
"@graphql-mesh/types": "1.0.0-alpha-
|
|
8
|
-
"@graphql-mesh/utils": "1.0.0-alpha-
|
|
9
|
-
"@graphql-tools/utils": "^9.2.1",
|
|
6
|
+
"@graphql-mesh/cross-helpers": "0.4.0-alpha-20230523154231-8c60b52d9",
|
|
7
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230523154231-8c60b52d9",
|
|
8
|
+
"@graphql-mesh/utils": "1.0.0-alpha-20230523154231-8c60b52d9",
|
|
9
|
+
"@graphql-tools/utils": "^9.2.1 || ^10.0.0",
|
|
10
10
|
"graphql": "*",
|
|
11
11
|
"tslib": "^2.4.0"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@graphql-mesh/string-interpolation": "0.5.0-alpha-
|
|
15
|
-
"@graphql-tools/mock": "^
|
|
16
|
-
"@graphql-tools/schema": "^
|
|
14
|
+
"@graphql-mesh/string-interpolation": "0.5.0-alpha-20230523154231-8c60b52d9",
|
|
15
|
+
"@graphql-tools/mock": "^9.0.0",
|
|
16
|
+
"@graphql-tools/schema": "^10.0.0",
|
|
17
17
|
"faker": "5.5.3",
|
|
18
18
|
"graphql-scalars": "^1.20.4"
|
|
19
19
|
},
|
|
@@ -23,9 +23,6 @@
|
|
|
23
23
|
"directory": "packages/plugins/mock"
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
|
-
"engines": {
|
|
27
|
-
"node": ">=16.0.0"
|
|
28
|
-
},
|
|
29
26
|
"main": "cjs/index.js",
|
|
30
27
|
"module": "esm/index.js",
|
|
31
28
|
"typings": "typings/index.d.ts",
|