@0no-co/graphql.web 0.1.4 → 0.1.5

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.
@@ -22,13 +22,14 @@ class GraphQLError extends Error {
22
22
  if (a) {
23
23
  this.originalError = a;
24
24
  }
25
- if (!o && a) {
26
- var l = a.extensions;
27
- if (l && "object" == typeof l) {
28
- l;
25
+ var l = o;
26
+ if (!l && a) {
27
+ var u = a.extensions;
28
+ if (u && "object" == typeof u) {
29
+ l = u;
29
30
  }
30
31
  }
31
- this.extensions = o || {};
32
+ this.extensions = l || {};
32
33
  }
33
34
  toJSON() {
34
35
  return {
@@ -61,43 +62,44 @@ function advance(i) {
61
62
  var i = / +(?=[^\s])/y;
62
63
 
63
64
  function blockString(e) {
64
- var r = "";
65
- var n = 0;
65
+ var r = e.split("\n");
66
+ var n = "";
66
67
  var t = 0;
67
- var a = -1;
68
- var o = e.split("\n");
69
- for (var l = 0; l < o.length; l++) {
68
+ var a = 0;
69
+ var o = r.length - 1;
70
+ for (var l = 0; l < r.length; l++) {
70
71
  i.lastIndex = 0;
71
- if (i.test(o[l])) {
72
- if (l && (!n || i.lastIndex < n)) {
73
- n = i.lastIndex;
72
+ if (i.test(r[l])) {
73
+ if (l && (!t || i.lastIndex < t)) {
74
+ t = i.lastIndex;
74
75
  }
75
- t = t || l;
76
- a = l;
76
+ a = a || l;
77
+ o = l;
77
78
  }
78
79
  }
79
- for (var u = t; u <= a; u++) {
80
- if (u !== t) {
81
- r += "\n";
80
+ for (var u = a; u <= o; u++) {
81
+ if (u !== a) {
82
+ n += "\n";
82
83
  }
83
- r += o[u].slice(n).replace(/\\"""/g, '"""');
84
+ n += r[u].slice(t).replace(/\\"""/g, '"""');
84
85
  }
85
- return r;
86
+ return n;
86
87
  }
87
88
 
88
- var n = /(?:[\s,]*|#[^\n\r]*)*/y;
89
-
90
89
  function ignored() {
91
- n.lastIndex = r;
92
- n.test(e);
93
- r = n.lastIndex;
90
+ for (var i = 0 | e.charCodeAt(r++); 9 === i || 10 === i || 13 === i || 32 === i || 35 === i || 44 === i || 65279 === i; i = 0 | e.charCodeAt(r++)) {
91
+ if (35 === i) {
92
+ while (10 !== (i = e.charCodeAt(r++)) && 13 !== i) {}
93
+ }
94
+ }
95
+ r--;
94
96
  }
95
97
 
96
- var t = /[_\w][_\d\w]*/y;
98
+ var n = /[_\w][_\d\w]*/y;
97
99
 
98
100
  function name() {
99
101
  var e;
100
- if (e = advance(t)) {
102
+ if (e = advance(n)) {
101
103
  return {
102
104
  kind: "Name",
103
105
  value: e
@@ -105,66 +107,66 @@ function name() {
105
107
  }
106
108
  }
107
109
 
108
- var a = /null|true|false/y;
110
+ var t = /null|true|false/y;
109
111
 
110
- var o = /\$[_\w][_\d\w]*/y;
112
+ var a = /\$[_\w][_\d\w]*/y;
111
113
 
112
- var l = /[-]?\d+/y;
114
+ var o = /[-]?\d+/y;
113
115
 
114
- var u = /(?:[-]?\d+)?(?:\.\d+)(?:[eE][+-]?\d+)?/y;
116
+ var l = /(?:[-]?\d+)?(?:\.\d+)(?:[eE][+-]?\d+)?/y;
115
117
 
116
- var s = /\\/g;
118
+ var u = /\\/g;
117
119
 
118
120
  var d = /"""(?:[\s\S]+(?="""))?"""/y;
119
121
 
120
122
  var v = /"(?:[^"\r\n]+)?"/y;
121
123
 
122
124
  function value(i) {
123
- var n;
125
+ var s;
124
126
  var c;
125
- if (c = advance(a)) {
126
- n = "null" === c ? {
127
+ if (c = advance(t)) {
128
+ s = "null" === c ? {
127
129
  kind: "NullValue"
128
130
  } : {
129
131
  kind: "BooleanValue",
130
132
  value: "true" === c
131
133
  };
132
- } else if (!i && (c = advance(o))) {
133
- n = {
134
+ } else if (!i && (c = advance(a))) {
135
+ s = {
134
136
  kind: "Variable",
135
137
  name: {
136
138
  kind: "Name",
137
139
  value: c.slice(1)
138
140
  }
139
141
  };
140
- } else if (c = advance(u)) {
141
- n = {
142
+ } else if (c = advance(l)) {
143
+ s = {
142
144
  kind: "FloatValue",
143
145
  value: c
144
146
  };
145
- } else if (c = advance(l)) {
146
- n = {
147
+ } else if (c = advance(o)) {
148
+ s = {
147
149
  kind: "IntValue",
148
150
  value: c
149
151
  };
150
- } else if (c = advance(t)) {
151
- n = {
152
+ } else if (c = advance(n)) {
153
+ s = {
152
154
  kind: "EnumValue",
153
155
  value: c
154
156
  };
155
157
  } else if (c = advance(d)) {
156
- n = {
158
+ s = {
157
159
  kind: "StringValue",
158
160
  value: blockString(c.slice(3, -3)),
159
161
  block: !0
160
162
  };
161
163
  } else if (c = advance(v)) {
162
- n = {
164
+ s = {
163
165
  kind: "StringValue",
164
- value: s.test(c) ? JSON.parse(c) : c.slice(1, -1),
166
+ value: u.test(c) ? JSON.parse(c) : c.slice(1, -1),
165
167
  block: !1
166
168
  };
167
- } else if (n = function list(i) {
169
+ } else if (s = function list(i) {
168
170
  var n;
169
171
  if (91 === e.charCodeAt(r)) {
170
172
  r++;
@@ -214,10 +216,10 @@ function value(i) {
214
216
  };
215
217
  }
216
218
  }(i)) {
217
- return n;
219
+ return s;
218
220
  }
219
221
  ignored();
220
- return n;
222
+ return s;
221
223
  }
222
224
 
223
225
  function arguments_(i) {
@@ -271,7 +273,6 @@ function directives(i) {
271
273
  }
272
274
 
273
275
  function field() {
274
- ignored();
275
276
  var i = name();
276
277
  if (i) {
277
278
  ignored();
@@ -331,10 +332,10 @@ function type() {
331
332
  }
332
333
  }
333
334
 
334
- var c = /on/y;
335
+ var s = /on/y;
335
336
 
336
337
  function typeCondition() {
337
- if (advance(c)) {
338
+ if (advance(s)) {
338
339
  ignored();
339
340
  var e = name();
340
341
  if (!e) {
@@ -348,11 +349,10 @@ function typeCondition() {
348
349
  }
349
350
  }
350
351
 
351
- var f = /\.\.\./y;
352
+ var c = /\.\.\./y;
352
353
 
353
354
  function fragmentSpread() {
354
- ignored();
355
- if (advance(f)) {
355
+ if (advance(c)) {
356
356
  ignored();
357
357
  var e = r;
358
358
  var i;
@@ -401,10 +401,10 @@ function selectionSet() {
401
401
  }
402
402
  }
403
403
 
404
- var p = /fragment/y;
404
+ var f = /fragment/y;
405
405
 
406
406
  function fragmentDefinition() {
407
- if (advance(p)) {
407
+ if (advance(f)) {
408
408
  ignored();
409
409
  var e = name();
410
410
  if (!e) {
@@ -430,14 +430,14 @@ function fragmentDefinition() {
430
430
  }
431
431
  }
432
432
 
433
- var m = /query|mutation|subscription/y;
433
+ var p = /query|mutation|subscription/y;
434
434
 
435
435
  function operationDefinition() {
436
436
  var i;
437
437
  var n;
438
438
  var t = [];
439
- var a = [];
440
- if (i = advance(m)) {
439
+ var o = [];
440
+ if (i = advance(p)) {
441
441
  ignored();
442
442
  n = name();
443
443
  t = function variableDefinitions() {
@@ -447,7 +447,7 @@ function operationDefinition() {
447
447
  if (40 === e.charCodeAt(r)) {
448
448
  r++;
449
449
  ignored();
450
- while (i = advance(o)) {
450
+ while (i = advance(a)) {
451
451
  ignored();
452
452
  if (58 !== e.charCodeAt(r++)) {
453
453
  throw error("VariableDefinition");
@@ -456,11 +456,11 @@ function operationDefinition() {
456
456
  if (!t) {
457
457
  throw error("VariableDefinition");
458
458
  }
459
- var a = void 0;
459
+ var o = void 0;
460
460
  if (61 === e.charCodeAt(r)) {
461
461
  r++;
462
462
  ignored();
463
- if (!(a = value(!0))) {
463
+ if (!(o = value(!0))) {
464
464
  throw error("VariableDefinition");
465
465
  }
466
466
  }
@@ -475,7 +475,7 @@ function operationDefinition() {
475
475
  }
476
476
  },
477
477
  type: t,
478
- defaultValue: a,
478
+ defaultValue: o,
479
479
  directives: directives(!0)
480
480
  });
481
481
  }
@@ -486,7 +486,7 @@ function operationDefinition() {
486
486
  }
487
487
  return n;
488
488
  }();
489
- a = directives(!1);
489
+ o = directives(!1);
490
490
  }
491
491
  var l = selectionSet();
492
492
  if (l) {
@@ -495,13 +495,13 @@ function operationDefinition() {
495
495
  operation: i || "query",
496
496
  name: n,
497
497
  variableDefinitions: t,
498
- directives: a,
498
+ directives: o,
499
499
  selectionSet: l
500
500
  };
501
501
  }
502
502
  }
503
503
 
504
- var g = {};
504
+ var m = {};
505
505
 
506
506
  function printString(e) {
507
507
  return JSON.stringify(e);
@@ -513,7 +513,102 @@ function printBlockString(e) {
513
513
 
514
514
  var hasItems = e => !(!e || !e.length);
515
515
 
516
- var h = 80;
516
+ var g = {
517
+ OperationDefinition(e) {
518
+ if ("query" === e.operation && !e.name && !hasItems(e.variableDefinitions) && !hasItems(e.directives)) {
519
+ return g.SelectionSet(e.selectionSet);
520
+ }
521
+ var r = e.operation;
522
+ if (e.name) {
523
+ r += " " + e.name.value;
524
+ }
525
+ if (hasItems(e.variableDefinitions)) {
526
+ if (!e.name) {
527
+ r += " ";
528
+ }
529
+ r += "(" + e.variableDefinitions.map(g.VariableDefinition).join(", ") + ")";
530
+ }
531
+ if (hasItems(e.directives)) {
532
+ r += " " + e.directives.map(g.Directive).join(" ");
533
+ }
534
+ return r + " " + g.SelectionSet(e.selectionSet);
535
+ },
536
+ VariableDefinition(e) {
537
+ var r = g.Variable(e.variable) + ": " + print(e.type);
538
+ if (e.defaultValue) {
539
+ r += " = " + print(e.defaultValue);
540
+ }
541
+ if (hasItems(e.directives)) {
542
+ r += " " + e.directives.map(g.Directive).join(" ");
543
+ }
544
+ return r;
545
+ },
546
+ Field(e) {
547
+ var r = (e.alias ? e.alias.value + ": " : "") + e.name.value;
548
+ if (hasItems(e.arguments)) {
549
+ var i = e.arguments.map(g.Argument);
550
+ var n = r + "(" + i.join(", ") + ")";
551
+ r = n.length > 80 ? r + "(\n " + i.join("\n").replace(/\n/g, "\n ") + "\n)" : n;
552
+ }
553
+ if (hasItems(e.directives)) {
554
+ r += " " + e.directives.map(g.Directive).join(" ");
555
+ }
556
+ return e.selectionSet ? r + " " + g.SelectionSet(e.selectionSet) : r;
557
+ },
558
+ StringValue: e => e.block ? printBlockString(e.value) : printString(e.value),
559
+ BooleanValue: e => "" + e.value,
560
+ NullValue: e => "null",
561
+ IntValue: e => e.value,
562
+ FloatValue: e => e.value,
563
+ EnumValue: e => e.value,
564
+ Name: e => e.value,
565
+ Variable: e => "$" + e.name.value,
566
+ ListValue: e => "[" + e.values.map(print).join(", ") + "]",
567
+ ObjectValue: e => "{" + e.fields.map(g.ObjectField).join(", ") + "}",
568
+ ObjectField: e => e.name.value + ": " + print(e.value),
569
+ Document: e => hasItems(e.definitions) ? e.definitions.map(print).join("\n\n") : "",
570
+ SelectionSet: e => "{\n " + e.selections.map(print).join("\n").replace(/\n/g, "\n ") + "\n}",
571
+ Argument: e => e.name.value + ": " + print(e.value),
572
+ FragmentSpread(e) {
573
+ var r = "..." + e.name.value;
574
+ if (hasItems(e.directives)) {
575
+ r += " " + e.directives.map(g.Directive).join(" ");
576
+ }
577
+ return r;
578
+ },
579
+ InlineFragment(e) {
580
+ var r = "...";
581
+ if (e.typeCondition) {
582
+ r += " on " + e.typeCondition.name.value;
583
+ }
584
+ if (hasItems(e.directives)) {
585
+ r += " " + e.directives.map(g.Directive).join(" ");
586
+ }
587
+ return r + " " + print(e.selectionSet);
588
+ },
589
+ FragmentDefinition(e) {
590
+ var r = "fragment " + e.name.value;
591
+ r += " on " + e.typeCondition.name.value;
592
+ if (hasItems(e.directives)) {
593
+ r += " " + e.directives.map(g.Directive).join(" ");
594
+ }
595
+ return r + " " + print(e.selectionSet);
596
+ },
597
+ Directive(e) {
598
+ var r = "@" + e.name.value;
599
+ if (hasItems(e.arguments)) {
600
+ r += "(" + e.arguments.map(g.Argument).join(", ") + ")";
601
+ }
602
+ return r;
603
+ },
604
+ NamedType: e => e.name.value,
605
+ ListType: e => "[" + print(e.type) + "]",
606
+ NonNullType: e => print(e.type) + "!"
607
+ };
608
+
609
+ function print(e) {
610
+ return g[e.kind] ? g[e.kind](e) : "";
611
+ }
517
612
 
518
613
  function valueFromASTUntyped(e, r) {
519
614
  switch (e.kind) {
@@ -551,7 +646,7 @@ function valueFromASTUntyped(e, r) {
551
646
  }
552
647
  }
553
648
 
554
- exports.BREAK = g;
649
+ exports.BREAK = m;
555
650
 
556
651
  exports.GraphQLError = GraphQLError;
557
652
 
@@ -567,6 +662,13 @@ exports.Kind = {
567
662
  INLINE_FRAGMENT: "InlineFragment",
568
663
  FRAGMENT_DEFINITION: "FragmentDefinition",
569
664
  VARIABLE: "Variable",
665
+ INT: "IntValue",
666
+ FLOAT: "FloatValue",
667
+ STRING: "StringValue",
668
+ BOOLEAN: "BooleanValue",
669
+ NULL: "NullValue",
670
+ ENUM: "EnumValue",
671
+ LIST: "ListValue",
570
672
  OBJECT: "ObjectValue",
571
673
  OBJECT_FIELD: "ObjectField",
572
674
  DIRECTIVE: "Directive",
@@ -624,129 +726,7 @@ exports.parseValue = function parseValue(i, n) {
624
726
  return t;
625
727
  };
626
728
 
627
- exports.print = function print(e) {
628
- var r;
629
- switch (e.kind) {
630
- case "OperationDefinition":
631
- if ("query" === e.operation && !e.name && !hasItems(e.variableDefinitions) && !hasItems(e.directives)) {
632
- return print(e.selectionSet);
633
- }
634
- r = e.operation;
635
- if (e.name) {
636
- r += " " + e.name.value;
637
- }
638
- if (hasItems(e.variableDefinitions)) {
639
- if (!e.name) {
640
- r += " ";
641
- }
642
- r += "(" + e.variableDefinitions.map(print).join(", ") + ")";
643
- }
644
- if (hasItems(e.directives)) {
645
- r += " " + e.directives.map(print).join(" ");
646
- }
647
- return r + " " + print(e.selectionSet);
648
-
649
- case "VariableDefinition":
650
- r = print(e.variable) + ": " + print(e.type);
651
- if (e.defaultValue) {
652
- r += " = " + print(e.defaultValue);
653
- }
654
- if (hasItems(e.directives)) {
655
- r += " " + e.directives.map(print).join(" ");
656
- }
657
- return r;
658
-
659
- case "Field":
660
- r = (e.alias ? print(e.alias) + ": " : "") + e.name.value;
661
- if (hasItems(e.arguments)) {
662
- var i = e.arguments.map(print);
663
- var n = r + "(" + i.join(", ") + ")";
664
- r = n.length > h ? r + "(\n " + i.join("\n").replace(/\n/g, "\n ") + "\n)" : n;
665
- }
666
- if (hasItems(e.directives)) {
667
- r += " " + e.directives.map(print).join(" ");
668
- }
669
- return e.selectionSet ? r + " " + print(e.selectionSet) : r;
670
-
671
- case "StringValue":
672
- return e.block ? printBlockString(e.value) : printString(e.value);
673
-
674
- case "BooleanValue":
675
- return "" + e.value;
676
-
677
- case "NullValue":
678
- return "null";
679
-
680
- case "IntValue":
681
- case "FloatValue":
682
- case "EnumValue":
683
- case "Name":
684
- return e.value;
685
-
686
- case "ListValue":
687
- return "[" + e.values.map(print).join(", ") + "]";
688
-
689
- case "ObjectValue":
690
- return "{" + e.fields.map(print).join(", ") + "}";
691
-
692
- case "ObjectField":
693
- case "Argument":
694
- return e.name.value + ": " + print(e.value);
695
-
696
- case "Variable":
697
- return "$" + e.name.value;
698
-
699
- case "Document":
700
- return hasItems(e.definitions) ? e.definitions.map(print).join("\n\n") : "";
701
-
702
- case "SelectionSet":
703
- return "{\n " + e.selections.map(print).join("\n").replace(/\n/g, "\n ") + "\n}";
704
-
705
- case "FragmentSpread":
706
- r = "..." + e.name.value;
707
- if (hasItems(e.directives)) {
708
- r += " " + e.directives.map(print).join(" ");
709
- }
710
- return r;
711
-
712
- case "InlineFragment":
713
- r = "...";
714
- if (e.typeCondition) {
715
- r += " on " + e.typeCondition.name.value;
716
- }
717
- if (hasItems(e.directives)) {
718
- r += " " + e.directives.map(print).join(" ");
719
- }
720
- return r + " " + print(e.selectionSet);
721
-
722
- case "FragmentDefinition":
723
- r = "fragment " + e.name.value;
724
- r += " on " + e.typeCondition.name.value;
725
- if (hasItems(e.directives)) {
726
- r += " " + e.directives.map(print).join(" ");
727
- }
728
- return r + " " + print(e.selectionSet);
729
-
730
- case "Directive":
731
- r = "@" + e.name.value;
732
- if (hasItems(e.arguments)) {
733
- r += "(" + e.arguments.map(print).join(", ") + ")";
734
- }
735
- return r;
736
-
737
- case "NamedType":
738
- return e.name.value;
739
-
740
- case "ListType":
741
- return "[" + print(e.type) + "]";
742
-
743
- case "NonNullType":
744
- return print(e.type) + "!";
745
-
746
- default:
747
- return "";
748
- }
749
- };
729
+ exports.print = print;
750
730
 
751
731
  exports.printBlockString = printBlockString;
752
732
 
@@ -794,14 +774,14 @@ exports.visit = function visit(e, r) {
794
774
  try {
795
775
  var t = function traverse(e, t, a) {
796
776
  var o = !1;
797
- var l = r[e.kind] && r[e.kind].enter || r[e.kind];
777
+ var l = r[e.kind] && r[e.kind].enter || r[e.kind] || r.enter;
798
778
  var u = l && l.call(r, e, t, a, n, i);
799
779
  if (!1 === u) {
800
780
  return e;
801
781
  } else if (null === u) {
802
782
  return null;
803
- } else if (u === g) {
804
- throw g;
783
+ } else if (u === m) {
784
+ throw m;
805
785
  } else if (u && "string" == typeof u.kind) {
806
786
  o = u !== e;
807
787
  e = u;
@@ -809,62 +789,62 @@ exports.visit = function visit(e, r) {
809
789
  if (a) {
810
790
  i.push(a);
811
791
  }
812
- var s;
813
- var d = {
792
+ var d;
793
+ var v = {
814
794
  ...e
815
795
  };
816
- for (var v in e) {
817
- n.push(v);
818
- var c = e[v];
796
+ for (var s in e) {
797
+ n.push(s);
798
+ var c = e[s];
819
799
  if (Array.isArray(c)) {
820
800
  var f = [];
821
801
  for (var p = 0; p < c.length; p++) {
822
802
  if (null != c[p] && "string" == typeof c[p].kind) {
823
803
  i.push(e);
824
804
  n.push(p);
825
- s = traverse(c[p], p, c);
805
+ d = traverse(c[p], p, c);
826
806
  n.pop();
827
807
  i.pop();
828
- if (void 0 === s) {
808
+ if (void 0 === d) {
829
809
  f.push(c[p]);
830
- } else if (null === s) {
810
+ } else if (null === d) {
831
811
  o = !0;
832
812
  } else {
833
- o = o || s !== c[p];
834
- f.push(s);
813
+ o = o || d !== c[p];
814
+ f.push(d);
835
815
  }
836
816
  }
837
817
  }
838
818
  c = f;
839
819
  } else if (null != c && "string" == typeof c.kind) {
840
- if (void 0 !== (s = traverse(c, v, e))) {
841
- o = o || c !== s;
842
- c = s;
820
+ if (void 0 !== (d = traverse(c, s, e))) {
821
+ o = o || c !== d;
822
+ c = d;
843
823
  }
844
824
  }
845
825
  n.pop();
846
826
  if (o) {
847
- d[v] = c;
827
+ v[s] = c;
848
828
  }
849
829
  }
850
830
  if (a) {
851
831
  i.pop();
852
832
  }
853
- var m = r[e.kind] && r[e.kind].leave;
854
- var h = m && m.call(r, e, t, a, n, i);
855
- if (h === g) {
856
- throw g;
833
+ var g = r[e.kind] && r[e.kind].leave || r.leave;
834
+ var h = g && g.call(r, e, t, a, n, i);
835
+ if (h === m) {
836
+ throw m;
857
837
  } else if (void 0 !== h) {
858
838
  return h;
859
839
  } else if (void 0 !== u) {
860
- return o ? d : u;
840
+ return o ? v : u;
861
841
  } else {
862
- return o ? d : e;
842
+ return o ? v : e;
863
843
  }
864
844
  }(e);
865
845
  return void 0 !== t && !1 !== t ? t : e;
866
846
  } catch (r) {
867
- if (r !== g) {
847
+ if (r !== m) {
868
848
  throw r;
869
849
  }
870
850
  return e;