@graphql-codegen/hasura-allow-list 1.0.2-alpha-4a7e799f2.0 → 1.1.0-alpha-29eb1293b.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/cjs/config.js
ADDED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const graphql = require('graphql');
|
|
8
|
-
const yaml = _interopDefault(require('yaml'));
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.plugin = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const graphql_1 = require("graphql");
|
|
6
|
+
const yaml_1 = tslib_1.__importDefault(require("yaml"));
|
|
10
7
|
/**
|
|
11
8
|
* Returns an array of fragments required for a given operation, recursively.
|
|
12
9
|
* Will throw an error if it cannot find one of the fragments required for the operation.
|
|
@@ -26,7 +23,7 @@ function getOperationFragmentsRecursively(operationDefinition, fragmentDefinitio
|
|
|
26
23
|
* @param definition either an operation definition or a fragment definition.
|
|
27
24
|
*/
|
|
28
25
|
function getRequiredFragments(definition) {
|
|
29
|
-
|
|
26
|
+
(0, graphql_1.visit)(definition, {
|
|
30
27
|
FragmentSpread(fragmentSpreadNode) {
|
|
31
28
|
// added this check to prevent infinite recursion on recursive fragment definition (which itself isn't legal graphql)
|
|
32
29
|
// it seems graphql crashes anyways if a recursive fragment is defined, so maybe remove this check?
|
|
@@ -34,7 +31,7 @@ function getOperationFragmentsRecursively(operationDefinition, fragmentDefinitio
|
|
|
34
31
|
requiredFragmentNames.add(fragmentSpreadNode.name.value);
|
|
35
32
|
const fragmentDefinition = fragmentDefinitions.find(definition => definition.name.value === fragmentSpreadNode.name.value);
|
|
36
33
|
if (!fragmentDefinition) {
|
|
37
|
-
throw new Error(`Missing fragment ${fragmentSpreadNode.name.value} for ${definition.kind ===
|
|
34
|
+
throw new Error(`Missing fragment ${fragmentSpreadNode.name.value} for ${definition.kind === graphql_1.Kind.FRAGMENT_DEFINITION ? 'fragment' : 'operation'} ${definition.name.value} in file ${documentLocation}`);
|
|
38
35
|
}
|
|
39
36
|
else {
|
|
40
37
|
getRequiredFragments(fragmentDefinition);
|
|
@@ -52,9 +49,9 @@ const plugin = async (schema, documents, config) => {
|
|
|
52
49
|
// any fragment required by an operation will need to be definied in the same file as the operation.
|
|
53
50
|
for (const document of documents) {
|
|
54
51
|
// filter out anonymous operations
|
|
55
|
-
const documentOperations = document.document.definitions.filter((definition) => definition.kind ===
|
|
52
|
+
const documentOperations = document.document.definitions.filter((definition) => definition.kind === graphql_1.Kind.OPERATION_DEFINITION && !!definition.name);
|
|
56
53
|
// filter out anonymous fragments
|
|
57
|
-
const documentFragments = document.document.definitions.filter((definition) => definition.kind ===
|
|
54
|
+
const documentFragments = document.document.definitions.filter((definition) => definition.kind === graphql_1.Kind.FRAGMENT_DEFINITION && !!definition.name);
|
|
58
55
|
// for each operation in the document
|
|
59
56
|
for (const operation of documentOperations) {
|
|
60
57
|
// get fragments required by the operations
|
|
@@ -63,11 +60,11 @@ const plugin = async (schema, documents, config) => {
|
|
|
63
60
|
// fragment order is preserved, and each fragment is separated by a new line
|
|
64
61
|
queries.push({
|
|
65
62
|
name: operation.name.value,
|
|
66
|
-
query: [operation, ...requiredFragmentDefinitions].map(
|
|
63
|
+
query: [operation, ...requiredFragmentDefinitions].map(graphql_1.print).join('\n'),
|
|
67
64
|
});
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
|
-
return
|
|
67
|
+
return yaml_1.default.stringify([
|
|
71
68
|
{
|
|
72
69
|
name: (_a = config.collection_name) !== null && _a !== void 0 ? _a : 'allowed-queries',
|
|
73
70
|
definition: {
|
|
@@ -76,7 +73,5 @@ const plugin = async (schema, documents, config) => {
|
|
|
76
73
|
},
|
|
77
74
|
]);
|
|
78
75
|
};
|
|
79
|
-
const index = { plugin };
|
|
80
|
-
|
|
81
|
-
exports.default = index;
|
|
82
76
|
exports.plugin = plugin;
|
|
77
|
+
exports.default = { plugin: exports.plugin };
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
package/esm/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Kind, print, visit } from 'graphql';
|
|
1
|
+
import { Kind, print, visit, } from 'graphql';
|
|
2
2
|
import yaml from 'yaml';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* Returns an array of fragments required for a given operation, recursively.
|
|
6
5
|
* Will throw an error if it cannot find one of the fragments required for the operation.
|
|
@@ -39,7 +38,7 @@ function getOperationFragmentsRecursively(operationDefinition, fragmentDefinitio
|
|
|
39
38
|
});
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
|
-
const plugin = async (schema, documents, config) => {
|
|
41
|
+
export const plugin = async (schema, documents, config) => {
|
|
43
42
|
var _a;
|
|
44
43
|
const queries = [];
|
|
45
44
|
// each document (graphql file) is handled independently.
|
|
@@ -70,7 +69,4 @@ const plugin = async (schema, documents, config) => {
|
|
|
70
69
|
},
|
|
71
70
|
]);
|
|
72
71
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
export default index;
|
|
76
|
-
export { plugin };
|
|
72
|
+
export default { plugin };
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/hasura-allow-list",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0-alpha-29eb1293b.0",
|
|
4
4
|
"description": "GraphQL Code Generator plugin to generate hasura allow liste metadata from graphql files",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "2.
|
|
10
|
-
"tslib": "~2.
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "^2.5.0-alpha-29eb1293b.0",
|
|
10
|
+
"tslib": "~2.4.0",
|
|
11
11
|
"yaml": "^1.10.2"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
@@ -16,21 +16,28 @@
|
|
|
16
16
|
"directory": "packages/plugins/other/hasura-allow-list"
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
|
-
"main": "index.js",
|
|
20
|
-
"module": "index.
|
|
21
|
-
"typings": "index.d.ts",
|
|
19
|
+
"main": "cjs/index.js",
|
|
20
|
+
"module": "esm/index.js",
|
|
21
|
+
"typings": "typings/index.d.ts",
|
|
22
22
|
"typescript": {
|
|
23
|
-
"definition": "index.d.ts"
|
|
23
|
+
"definition": "typings/index.d.ts"
|
|
24
24
|
},
|
|
25
|
+
"type": "module",
|
|
25
26
|
"exports": {
|
|
26
|
-
"./package.json": "./package.json",
|
|
27
27
|
".": {
|
|
28
|
-
"require":
|
|
29
|
-
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./typings/index.d.ts",
|
|
30
|
+
"default": "./cjs/index.js"
|
|
31
|
+
},
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./typings/index.d.ts",
|
|
34
|
+
"default": "./esm/index.js"
|
|
35
|
+
},
|
|
36
|
+
"default": {
|
|
37
|
+
"types": "./typings/index.d.ts",
|
|
38
|
+
"default": "./esm/index.js"
|
|
39
|
+
}
|
|
30
40
|
},
|
|
31
|
-
"
|
|
32
|
-
"require": "./*.js",
|
|
33
|
-
"import": "./*.mjs"
|
|
34
|
-
}
|
|
41
|
+
"./package.json": "./package.json"
|
|
35
42
|
}
|
|
36
|
-
}
|
|
43
|
+
}
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PluginFunction, Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
-
import { HasuraAllowListPluginConfig } from './config';
|
|
2
|
+
import { HasuraAllowListPluginConfig } from './config.js';
|
|
3
3
|
export declare const plugin: PluginFunction<HasuraAllowListPluginConfig>;
|
|
4
4
|
declare const _default: {
|
|
5
5
|
plugin: PluginFunction<HasuraAllowListPluginConfig, Types.PluginOutput>;
|