graphql-query-merger 1.0.0 → 1.0.2

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/dist/index.es.js CHANGED
@@ -1,106 +1,102 @@
1
- var d = (c, t) => () => (t || c((t = { exports: {} }).exports, t), t.exports);
2
- var T = d((A, m) => {
3
- const { Kind: i, parse: E, visit: N } = require("graphql");
4
- function I(c, t, s) {
5
- const o = {}, l = {}, r = N(c, {
6
- [i.VARIABLE_DEFINITION](e) {
7
- const n = e.variable.name.value, a = `${n}_${s}`;
8
- return o[n] = a, {
9
- ...e,
10
- variable: {
11
- ...e.variable,
12
- name: { kind: i.NAME, value: a }
13
- }
14
- };
15
- },
16
- [i.VARIABLE](e) {
17
- const n = e.name.value, a = o[n] || n;
18
- return {
19
- ...e,
20
- name: { kind: i.NAME, value: a }
21
- };
22
- },
23
- [i.FRAGMENT_DEFINITION](e) {
24
- const n = e.name.value, a = `${n}_${s}`;
25
- return l[n] = a, {
26
- ...e,
27
- name: { kind: i.NAME, value: a }
28
- };
29
- },
30
- [i.FRAGMENT_SPREAD](e) {
31
- const n = e.name.value, a = l[n] || n;
32
- return {
33
- ...e,
34
- name: { kind: i.NAME, value: a }
35
- };
36
- },
37
- [i.DIRECTIVE](e) {
38
- return N(e, {
39
- [i.VARIABLE](n) {
40
- const a = n.name.value, p = o[a] || a;
41
- return {
42
- ...n,
43
- name: { kind: i.NAME, value: p }
44
- };
45
- }
46
- });
47
- }
48
- }), u = {};
49
- for (const [e, n] of Object.entries(t)) {
50
- const a = o[e] || e;
51
- u[a] = n;
52
- }
53
- return { document: r, variables: u };
54
- }
55
- class f {
56
- constructor(t) {
57
- this.operationName = t, this.documents = [], this.internalVariables = [], this.uniqueIdCounter = 1, this.operationType = null;
58
- }
59
- push(t, s = {}) {
60
- typeof t == "string" && (t = E(t));
61
- const o = this.uniqueIdCounter++, { document: l, variables: r } = I(t, s, o), u = l.definitions.filter(
62
- (n) => n.kind === i.OPERATION_DEFINITION
63
- );
64
- if (u.length === 0)
65
- throw new Error(
66
- "No se encontró una definición de operación en el documento proporcionado."
67
- );
68
- const e = u[0].operation;
69
- if (this.operationType && this.operationType !== e)
70
- throw new Error(
71
- `No se pueden combinar diferentes tipos de operaciones: ${this.operationType} y ${e}.`
72
- );
73
- return this.operationType = e, this.documents.push(l), this.internalVariables.push(r), this;
74
- }
75
- get query() {
76
- const t = [], s = [], o = [];
77
- for (const l of this.documents)
78
- for (const r of l.definitions)
79
- r.kind === i.OPERATION_DEFINITION ? (t.push(...r.variableDefinitions || []), s.push(...r.selectionSet.selections)) : r.kind === i.FRAGMENT_DEFINITION && o.push(r);
1
+ import { parse as p, Kind as i, visit as N } from "graphql";
2
+ const d = (u, a, r) => {
3
+ const o = {}, l = {}, s = N(u, {
4
+ [i.VARIABLE_DEFINITION](e) {
5
+ const n = e.variable.name.value, t = `${n}_${r}`;
6
+ return o[n] = t, {
7
+ ...e,
8
+ variable: {
9
+ ...e.variable,
10
+ name: { kind: i.NAME, value: t }
11
+ }
12
+ };
13
+ },
14
+ [i.VARIABLE](e) {
15
+ const n = e.name.value, t = o[n] || n;
80
16
  return {
81
- kind: i.DOCUMENT,
82
- definitions: [
83
- {
84
- kind: i.OPERATION_DEFINITION,
85
- operation: this.operationType,
86
- name: { kind: i.NAME, value: this.operationName || "" },
87
- variableDefinitions: t,
88
- selectionSet: {
89
- kind: i.SELECTION_SET,
90
- selections: s
91
- }
92
- },
93
- ...o
94
- ]
17
+ ...e,
18
+ name: { kind: i.NAME, value: t }
95
19
  };
20
+ },
21
+ [i.FRAGMENT_DEFINITION](e) {
22
+ const n = e.name.value, t = `${n}_${r}`;
23
+ return l[n] = t, {
24
+ ...e,
25
+ name: { kind: i.NAME, value: t }
26
+ };
27
+ },
28
+ [i.FRAGMENT_SPREAD](e) {
29
+ const n = e.name.value, t = l[n] || n;
30
+ return {
31
+ ...e,
32
+ name: { kind: i.NAME, value: t }
33
+ };
34
+ },
35
+ [i.DIRECTIVE](e) {
36
+ return N(e, {
37
+ [i.VARIABLE](n) {
38
+ const t = n.name.value, m = o[t] || t;
39
+ return {
40
+ ...n,
41
+ name: { kind: i.NAME, value: m }
42
+ };
43
+ }
44
+ });
96
45
  }
97
- get variables() {
98
- return Object.assign({}, ...this.internalVariables);
99
- }
46
+ }), c = {};
47
+ for (const [e, n] of Object.entries(a)) {
48
+ const t = o[e] || e;
49
+ c[t] = n;
50
+ }
51
+ return { document: s, variables: c };
52
+ };
53
+ class E {
54
+ constructor(a) {
55
+ this.operationName = a, this.documents = [], this.internalVariables = [], this.uniqueIdCounter = 1, this.operationType = null;
56
+ }
57
+ push(a, r = {}) {
58
+ typeof a == "string" && (a = p(a));
59
+ const o = this.uniqueIdCounter++, { document: l, variables: s } = d(a, r, o), c = l.definitions.filter(
60
+ (n) => n.kind === i.OPERATION_DEFINITION
61
+ );
62
+ if (c.length === 0)
63
+ throw new Error(
64
+ "No se encontró una definición de operación en el documento proporcionado."
65
+ );
66
+ const e = c[0].operation;
67
+ if (this.operationType && this.operationType !== e)
68
+ throw new Error(
69
+ `No se pueden combinar diferentes tipos de operaciones: ${this.operationType} y ${e}.`
70
+ );
71
+ return this.operationType = e, this.documents.push(l), this.internalVariables.push(s), this;
72
+ }
73
+ get query() {
74
+ const a = [], r = [], o = [];
75
+ for (const l of this.documents)
76
+ for (const s of l.definitions)
77
+ s.kind === i.OPERATION_DEFINITION ? (a.push(...s.variableDefinitions || []), r.push(...s.selectionSet.selections)) : s.kind === i.FRAGMENT_DEFINITION && o.push(s);
78
+ return {
79
+ kind: i.DOCUMENT,
80
+ definitions: [
81
+ {
82
+ kind: i.OPERATION_DEFINITION,
83
+ operation: this.operationType,
84
+ name: { kind: i.NAME, value: this.operationName || "" },
85
+ variableDefinitions: a,
86
+ selectionSet: {
87
+ kind: i.SELECTION_SET,
88
+ selections: r
89
+ }
90
+ },
91
+ ...o
92
+ ]
93
+ };
100
94
  }
101
- function h(c = "") {
102
- return new f(c);
95
+ get variables() {
96
+ return Object.assign({}, ...this.internalVariables);
103
97
  }
104
- m.exports = { mergeQueries: h };
105
- });
106
- export default T();
98
+ }
99
+ const h = (u = "") => new E(u);
100
+ export {
101
+ h as mergeQueries
102
+ };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(e){typeof define=="function"&&define.amd?define(e):e()})(function(){"use strict";const{Kind:e,parse:m,visit:N}=require("graphql");function p(c,a,r){const o={},l={},s=N(c,{[e.VARIABLE_DEFINITION](n){const i=n.variable.name.value,t=`${i}_${r}`;return o[i]=t,{...n,variable:{...n.variable,name:{kind:e.NAME,value:t}}}},[e.VARIABLE](n){const i=n.name.value,t=o[i]||i;return{...n,name:{kind:e.NAME,value:t}}},[e.FRAGMENT_DEFINITION](n){const i=n.name.value,t=`${i}_${r}`;return l[i]=t,{...n,name:{kind:e.NAME,value:t}}},[e.FRAGMENT_SPREAD](n){const i=n.name.value,t=l[i]||i;return{...n,name:{kind:e.NAME,value:t}}},[e.DIRECTIVE](n){return N(n,{[e.VARIABLE](i){const t=i.name.value,E=o[t]||t;return{...i,name:{kind:e.NAME,value:E}}}})}}),u={};for(const[n,i]of Object.entries(a)){const t=o[n]||n;u[t]=i}return{document:s,variables:u}}class d{constructor(a){this.operationName=a,this.documents=[],this.internalVariables=[],this.uniqueIdCounter=1,this.operationType=null}push(a,r={}){typeof a=="string"&&(a=m(a));const o=this.uniqueIdCounter++,{document:l,variables:s}=p(a,r,o),u=l.definitions.filter(i=>i.kind===e.OPERATION_DEFINITION);if(u.length===0)throw new Error("No se encontró una definición de operación en el documento proporcionado.");const n=u[0].operation;if(this.operationType&&this.operationType!==n)throw new Error(`No se pueden combinar diferentes tipos de operaciones: ${this.operationType} y ${n}.`);return this.operationType=n,this.documents.push(l),this.internalVariables.push(s),this}get query(){const a=[],r=[],o=[];for(const l of this.documents)for(const s of l.definitions)s.kind===e.OPERATION_DEFINITION?(a.push(...s.variableDefinitions||[]),r.push(...s.selectionSet.selections)):s.kind===e.FRAGMENT_DEFINITION&&o.push(s);return{kind:e.DOCUMENT,definitions:[{kind:e.OPERATION_DEFINITION,operation:this.operationType,name:{kind:e.NAME,value:this.operationName||""},variableDefinitions:a,selectionSet:{kind:e.SELECTION_SET,selections:r}},...o]}}get variables(){return Object.assign({},...this.internalVariables)}}function f(c=""){return new d(c)}module.exports={mergeQueries:f}});
1
+ (function(r,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("graphql")):typeof define=="function"&&define.amd?define(["exports","graphql"],e):(r=typeof globalThis<"u"?globalThis:r||self,e(r["graphql-query-merger"]={},r.graphql))})(this,function(r,e){"use strict";const l=(m,o,d)=>{const s={},u={},a=e.visit(m,{[e.Kind.VARIABLE_DEFINITION](n){const i=n.variable.name.value,t=`${i}_${d}`;return s[i]=t,{...n,variable:{...n.variable,name:{kind:e.Kind.NAME,value:t}}}},[e.Kind.VARIABLE](n){const i=n.name.value,t=s[i]||i;return{...n,name:{kind:e.Kind.NAME,value:t}}},[e.Kind.FRAGMENT_DEFINITION](n){const i=n.name.value,t=`${i}_${d}`;return u[i]=t,{...n,name:{kind:e.Kind.NAME,value:t}}},[e.Kind.FRAGMENT_SPREAD](n){const i=n.name.value,t=u[i]||i;return{...n,name:{kind:e.Kind.NAME,value:t}}},[e.Kind.DIRECTIVE](n){return e.visit(n,{[e.Kind.VARIABLE](i){const t=i.name.value,E=s[t]||t;return{...i,name:{kind:e.Kind.NAME,value:E}}}})}}),c={};for(const[n,i]of Object.entries(o)){const t=s[n]||n;c[t]=i}return{document:a,variables:c}};class N{constructor(o){this.operationName=o,this.documents=[],this.internalVariables=[],this.uniqueIdCounter=1,this.operationType=null}push(o,d={}){typeof o=="string"&&(o=e.parse(o));const s=this.uniqueIdCounter++,{document:u,variables:a}=l(o,d,s),c=u.definitions.filter(i=>i.kind===e.Kind.OPERATION_DEFINITION);if(c.length===0)throw new Error("No se encontró una definición de operación en el documento proporcionado.");const n=c[0].operation;if(this.operationType&&this.operationType!==n)throw new Error(`No se pueden combinar diferentes tipos de operaciones: ${this.operationType} y ${n}.`);return this.operationType=n,this.documents.push(u),this.internalVariables.push(a),this}get query(){const o=[],d=[],s=[];for(const u of this.documents)for(const a of u.definitions)a.kind===e.Kind.OPERATION_DEFINITION?(o.push(...a.variableDefinitions||[]),d.push(...a.selectionSet.selections)):a.kind===e.Kind.FRAGMENT_DEFINITION&&s.push(a);return{kind:e.Kind.DOCUMENT,definitions:[{kind:e.Kind.OPERATION_DEFINITION,operation:this.operationType,name:{kind:e.Kind.NAME,value:this.operationName||""},variableDefinitions:o,selectionSet:{kind:e.Kind.SELECTION_SET,selections:d}},...s]}}get variables(){return Object.assign({},...this.internalVariables)}}const f=(m="")=>new N(m);r.mergeQueries=f,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "graphql-query-merger",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Merge and unify multiple GraphQL queries into a single operation with field and variable conflict resolution.",
5
- "main": "dist/index.cjs.js",
5
+ "main": "dist/index.umd.js",
6
6
  "module": "dist/index.es.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "files": [