@graphql-codegen/hasura-allow-list 3.0.0 → 3.1.0-alpha-20231023073057-4083c3f43
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 +10 -4
- package/esm/index.js +10 -4
- package/package.json +1 -1
- package/typings/config.d.cts +5 -0
- package/typings/config.d.ts +5 -0
package/cjs/index.js
CHANGED
|
@@ -12,11 +12,17 @@ const yaml_1 = tslib_1.__importDefault(require("yaml"));
|
|
|
12
12
|
* @param documentLocation location of the document the operation is sourced from. Only used to improve error messages.
|
|
13
13
|
* @returns an array of fragments required for the operation.
|
|
14
14
|
*/
|
|
15
|
-
function getOperationFragmentsRecursively(operationDefinition, fragmentDefinitions, documentLocation) {
|
|
15
|
+
function getOperationFragmentsRecursively(operationDefinition, fragmentDefinitions, documentLocation, config) {
|
|
16
|
+
var _a;
|
|
16
17
|
const requiredFragmentNames = new Set();
|
|
17
18
|
getRequiredFragments(operationDefinition);
|
|
18
|
-
// note: we
|
|
19
|
-
|
|
19
|
+
// note: we should choose fragmentsOrder config that is compatible with other graphql-codegen plugins we use.
|
|
20
|
+
const order = (_a = config.fragmentsOrder) !== null && _a !== void 0 ? _a : 'global';
|
|
21
|
+
// order of fragments is determined by the order they are defined in the document.
|
|
22
|
+
if (order === 'document') {
|
|
23
|
+
return Array.from(requiredFragmentNames).map(name => fragmentDefinitions.find(definition => definition.name.value === name));
|
|
24
|
+
}
|
|
25
|
+
// order is determined by the global fragments definition order.
|
|
20
26
|
return fragmentDefinitions.filter(definition => requiredFragmentNames.has(definition.name.value));
|
|
21
27
|
/**
|
|
22
28
|
* Given a definition adds required fragments to requieredFragmentsNames, recursively.
|
|
@@ -94,7 +100,7 @@ const plugin = async (schema, documents, config) => {
|
|
|
94
100
|
// for each operation in the document
|
|
95
101
|
for (const operation of documentOperations) {
|
|
96
102
|
// get fragments required by the operations
|
|
97
|
-
const requiredFragmentDefinitions = getOperationFragmentsRecursively(operation, fragments, document.location);
|
|
103
|
+
const requiredFragmentDefinitions = getOperationFragmentsRecursively(operation, fragments, document.location, config);
|
|
98
104
|
// insert the operation and any fragments to our queries definition.
|
|
99
105
|
// fragment order is preserved, and each fragment is separated by a new line
|
|
100
106
|
queries.push({
|
package/esm/index.js
CHANGED
|
@@ -8,11 +8,17 @@ import yaml from 'yaml';
|
|
|
8
8
|
* @param documentLocation location of the document the operation is sourced from. Only used to improve error messages.
|
|
9
9
|
* @returns an array of fragments required for the operation.
|
|
10
10
|
*/
|
|
11
|
-
function getOperationFragmentsRecursively(operationDefinition, fragmentDefinitions, documentLocation) {
|
|
11
|
+
function getOperationFragmentsRecursively(operationDefinition, fragmentDefinitions, documentLocation, config) {
|
|
12
|
+
var _a;
|
|
12
13
|
const requiredFragmentNames = new Set();
|
|
13
14
|
getRequiredFragments(operationDefinition);
|
|
14
|
-
// note: we
|
|
15
|
-
|
|
15
|
+
// note: we should choose fragmentsOrder config that is compatible with other graphql-codegen plugins we use.
|
|
16
|
+
const order = (_a = config.fragmentsOrder) !== null && _a !== void 0 ? _a : 'global';
|
|
17
|
+
// order of fragments is determined by the order they are defined in the document.
|
|
18
|
+
if (order === 'document') {
|
|
19
|
+
return Array.from(requiredFragmentNames).map(name => fragmentDefinitions.find(definition => definition.name.value === name));
|
|
20
|
+
}
|
|
21
|
+
// order is determined by the global fragments definition order.
|
|
16
22
|
return fragmentDefinitions.filter(definition => requiredFragmentNames.has(definition.name.value));
|
|
17
23
|
/**
|
|
18
24
|
* Given a definition adds required fragments to requieredFragmentsNames, recursively.
|
|
@@ -90,7 +96,7 @@ export const plugin = async (schema, documents, config) => {
|
|
|
90
96
|
// for each operation in the document
|
|
91
97
|
for (const operation of documentOperations) {
|
|
92
98
|
// get fragments required by the operations
|
|
93
|
-
const requiredFragmentDefinitions = getOperationFragmentsRecursively(operation, fragments, document.location);
|
|
99
|
+
const requiredFragmentDefinitions = getOperationFragmentsRecursively(operation, fragments, document.location, config);
|
|
94
100
|
// insert the operation and any fragments to our queries definition.
|
|
95
101
|
// fragment order is preserved, and each fragment is separated by a new line
|
|
96
102
|
queries.push({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/hasura-allow-list",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0-alpha-20231023073057-4083c3f43",
|
|
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"
|
package/typings/config.d.cts
CHANGED
|
@@ -16,4 +16,9 @@ export interface HasuraAllowListPluginConfig {
|
|
|
16
16
|
* @description Whether to source fragments per-document, or globally. If set, will enforce fragment name uniqueness
|
|
17
17
|
*/
|
|
18
18
|
globalFragments?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* @default definition
|
|
21
|
+
* @description Whether to order fragments by global definition order, or by definition order in the document
|
|
22
|
+
*/
|
|
23
|
+
fragmentsOrder?: 'global' | 'document';
|
|
19
24
|
}
|
package/typings/config.d.ts
CHANGED
|
@@ -16,4 +16,9 @@ export interface HasuraAllowListPluginConfig {
|
|
|
16
16
|
* @description Whether to source fragments per-document, or globally. If set, will enforce fragment name uniqueness
|
|
17
17
|
*/
|
|
18
18
|
globalFragments?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* @default definition
|
|
21
|
+
* @description Whether to order fragments by global definition order, or by definition order in the document
|
|
22
|
+
*/
|
|
23
|
+
fragmentsOrder?: 'global' | 'document';
|
|
19
24
|
}
|