Skip to content

Commit

Permalink
🔧 Sort fields alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
adbouygues committed Aug 23, 2024
1 parent 4866c5d commit 87c54da
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
diff --git a/node_modules/@graphql-mesh/merger-stitching/cjs/index.js b/node_modules/@graphql-mesh/merger-stitching/cjs/index.js
index 381e473..951f14d 100644
--- a/node_modules/@graphql-mesh/merger-stitching/cjs/index.js
+++ b/node_modules/@graphql-mesh/merger-stitching/cjs/index.js
@@ -1,5 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+function sortKeys(dict) {
+ var sorted = [];
+ for(var key in dict) {
+ sorted[sorted.length] = key;
+ }
+ sorted.sort();
+ var tempDict = {};
+ for(var i = 0; i < sorted.length; i++) {
+ tempDict[sorted[i]] = dict[sorted[i]];
+ }
+ return tempDict;
+}
const stitch_1 = require("@graphql-tools/stitch");
class StitchingMerger {
constructor(options) {
@@ -42,6 +54,12 @@ class StitchingMerger {
},
}),
});
+
+ // Sort fields alphabetically
+ Object.keys(unifiedSchema._typeMap).forEach((type) => {
+ unifiedSchema._typeMap[type]._fields = sortKeys(unifiedSchema._typeMap[type]._fields);
+ });
+
return {
schema: unifiedSchema,
};
50 changes: 0 additions & 50 deletions packages/graphql-mesh/patches/@graphql-tools+stitch+9.0.3.patch
Original file line number Diff line number Diff line change
@@ -1,53 +1,3 @@
diff --git a/node_modules/@graphql-tools/stitch/cjs/mergeCandidates.js b/node_modules/@graphql-tools/stitch/cjs/mergeCandidates.js
index 819b2b6..006424f 100644
--- a/node_modules/@graphql-tools/stitch/cjs/mergeCandidates.js
+++ b/node_modules/@graphql-tools/stitch/cjs/mergeCandidates.js
@@ -5,6 +5,18 @@ const graphql_1 = require("graphql");
const delegate_1 = require("@graphql-tools/delegate");
const merge_1 = require("@graphql-tools/merge");
const mergeValidations_js_1 = require("./mergeValidations.js");
+function sortKeys(dict) {
+ var sorted = [];
+ for(var key in dict) {
+ sorted[sorted.length] = key;
+ }
+ sorted.sort();
+ var tempDict = {};
+ for(var i = 0; i < sorted.length; i++) {
+ tempDict[sorted[i]] = dict[sorted[i]];
+ }
+ return tempDict;
+}
function mergeCandidates(typeName, candidates, typeMergingOptions) {
const initialCandidateType = candidates[0].type;
if (candidates.some(candidate => candidate.type.constructor !== initialCandidateType.constructor)) {
@@ -37,7 +49,7 @@ exports.mergeCandidates = mergeCandidates;
function mergeObjectTypeCandidates(typeName, candidates, typeMergingOptions) {
candidates = orderedTypeCandidates(candidates, typeMergingOptions);
const description = mergeTypeDescriptions(candidates, typeMergingOptions);
- const fields = fieldConfigMapFromTypeCandidates(candidates, typeMergingOptions);
+ const fields = sortKeys(fieldConfigMapFromTypeCandidates(candidates, typeMergingOptions));
const typeConfigs = candidates.map(candidate => candidate.type.toConfig());
const interfaceMap = typeConfigs
.map(typeConfig => typeConfig.interfaces)
@@ -79,7 +91,7 @@ function mergeObjectTypeCandidates(typeName, candidates, typeMergingOptions) {
function mergeInputObjectTypeCandidates(typeName, candidates, typeMergingOptions) {
candidates = orderedTypeCandidates(candidates, typeMergingOptions);
const description = mergeTypeDescriptions(candidates, typeMergingOptions);
- const fields = inputFieldConfigMapFromTypeCandidates(candidates, typeMergingOptions);
+ const fields = sortKeys(inputFieldConfigMapFromTypeCandidates(candidates, typeMergingOptions));
const astNodes = pluck('astNode', candidates);
const fieldAstNodes = canonicalFieldNamesForType(candidates)
.map(fieldName => fields[fieldName]?.astNode)
@@ -113,7 +125,7 @@ function pluck(typeProperty, candidates) {
function mergeInterfaceTypeCandidates(typeName, candidates, typeMergingOptions) {
candidates = orderedTypeCandidates(candidates, typeMergingOptions);
const description = mergeTypeDescriptions(candidates, typeMergingOptions);
- const fields = fieldConfigMapFromTypeCandidates(candidates, typeMergingOptions);
+ const fields = sortKeys(fieldConfigMapFromTypeCandidates(candidates, typeMergingOptions));
const typeConfigs = candidates.map(candidate => candidate.type.toConfig());
const interfaceMap = typeConfigs
.map(typeConfig => ('interfaces' in typeConfig ? typeConfig.interfaces : []))
diff --git a/node_modules/@graphql-tools/stitch/cjs/mergeValidations.js b/node_modules/@graphql-tools/stitch/cjs/mergeValidations.js
index 5e752ad..3b487f5 100644
--- a/node_modules/@graphql-tools/stitch/cjs/mergeValidations.js
Expand Down

0 comments on commit 87c54da

Please sign in to comment.