@luvio/graphql-parser 5.43.1 → 5.44.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.
@@ -3,4 +3,4 @@ export type { ObjectValueNode, ListTypeNode, BooleanValueNode, EnumTypeDefinitio
3
3
  export { Kind } from 'graphql/language';
4
4
  export { gql, astResolver } from './gql';
5
5
  export type { AstResolver } from './gql';
6
- export { parse } from 'graphql/language';
6
+ export { parse, print } from 'graphql/language';
package/dist/v1/index.js CHANGED
@@ -606,7 +606,11 @@ const QueryDocumentKeys = {
606
606
  EnumTypeExtension: ["name", "directives", "values"],
607
607
  InputObjectTypeExtension: ["name", "directives", "fields"]
608
608
  };
609
- new Set(Object.keys(QueryDocumentKeys));
609
+ const kindValues = new Set(Object.keys(QueryDocumentKeys));
610
+ function isNode(maybeNode) {
611
+ const maybeKind = maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.kind;
612
+ return typeof maybeKind === "string" && kindValues.has(maybeKind);
613
+ }
610
614
  var OperationTypeNode;
611
615
  (function(OperationTypeNode2) {
612
616
  OperationTypeNode2["QUERY"] = "query";
@@ -637,14 +641,14 @@ function dedentBlockStringLines(lines) {
637
641
  for (let i = 0; i < lines.length; ++i) {
638
642
  var _firstNonEmptyLine;
639
643
  const line = lines[i];
640
- const indent = leadingWhitespace(line);
641
- if (indent === line.length) {
644
+ const indent2 = leadingWhitespace(line);
645
+ if (indent2 === line.length) {
642
646
  continue;
643
647
  }
644
648
  firstNonEmptyLine = (_firstNonEmptyLine = firstNonEmptyLine) !== null && _firstNonEmptyLine !== void 0 ? _firstNonEmptyLine : i;
645
649
  lastNonEmptyLine = i;
646
- if (i !== 0 && indent < commonIndent) {
647
- commonIndent = indent;
650
+ if (i !== 0 && indent2 < commonIndent) {
651
+ commonIndent = indent2;
648
652
  }
649
653
  }
650
654
  return lines.map((line, i) => i === 0 ? line : line.slice(commonIndent)).slice(
@@ -2488,6 +2492,547 @@ function getTokenDesc(token) {
2488
2492
  function getTokenKindDesc(kind) {
2489
2493
  return isPunctuatorTokenKind(kind) ? `"${kind}"` : kind;
2490
2494
  }
2495
+ function printString(str) {
2496
+ return `"${str.replace(escapedRegExp, escapedReplacer)}"`;
2497
+ }
2498
+ const escapedRegExp = /[\x00-\x1f\x22\x5c\x7f-\x9f]/g;
2499
+ function escapedReplacer(str) {
2500
+ return escapeSequences[str.charCodeAt(0)];
2501
+ }
2502
+ const escapeSequences = [
2503
+ "\\u0000",
2504
+ "\\u0001",
2505
+ "\\u0002",
2506
+ "\\u0003",
2507
+ "\\u0004",
2508
+ "\\u0005",
2509
+ "\\u0006",
2510
+ "\\u0007",
2511
+ "\\b",
2512
+ "\\t",
2513
+ "\\n",
2514
+ "\\u000B",
2515
+ "\\f",
2516
+ "\\r",
2517
+ "\\u000E",
2518
+ "\\u000F",
2519
+ "\\u0010",
2520
+ "\\u0011",
2521
+ "\\u0012",
2522
+ "\\u0013",
2523
+ "\\u0014",
2524
+ "\\u0015",
2525
+ "\\u0016",
2526
+ "\\u0017",
2527
+ "\\u0018",
2528
+ "\\u0019",
2529
+ "\\u001A",
2530
+ "\\u001B",
2531
+ "\\u001C",
2532
+ "\\u001D",
2533
+ "\\u001E",
2534
+ "\\u001F",
2535
+ "",
2536
+ "",
2537
+ '\\"',
2538
+ "",
2539
+ "",
2540
+ "",
2541
+ "",
2542
+ "",
2543
+ "",
2544
+ "",
2545
+ "",
2546
+ "",
2547
+ "",
2548
+ "",
2549
+ "",
2550
+ "",
2551
+ // 2F
2552
+ "",
2553
+ "",
2554
+ "",
2555
+ "",
2556
+ "",
2557
+ "",
2558
+ "",
2559
+ "",
2560
+ "",
2561
+ "",
2562
+ "",
2563
+ "",
2564
+ "",
2565
+ "",
2566
+ "",
2567
+ "",
2568
+ // 3F
2569
+ "",
2570
+ "",
2571
+ "",
2572
+ "",
2573
+ "",
2574
+ "",
2575
+ "",
2576
+ "",
2577
+ "",
2578
+ "",
2579
+ "",
2580
+ "",
2581
+ "",
2582
+ "",
2583
+ "",
2584
+ "",
2585
+ // 4F
2586
+ "",
2587
+ "",
2588
+ "",
2589
+ "",
2590
+ "",
2591
+ "",
2592
+ "",
2593
+ "",
2594
+ "",
2595
+ "",
2596
+ "",
2597
+ "",
2598
+ "\\\\",
2599
+ "",
2600
+ "",
2601
+ "",
2602
+ // 5F
2603
+ "",
2604
+ "",
2605
+ "",
2606
+ "",
2607
+ "",
2608
+ "",
2609
+ "",
2610
+ "",
2611
+ "",
2612
+ "",
2613
+ "",
2614
+ "",
2615
+ "",
2616
+ "",
2617
+ "",
2618
+ "",
2619
+ // 6F
2620
+ "",
2621
+ "",
2622
+ "",
2623
+ "",
2624
+ "",
2625
+ "",
2626
+ "",
2627
+ "",
2628
+ "",
2629
+ "",
2630
+ "",
2631
+ "",
2632
+ "",
2633
+ "",
2634
+ "",
2635
+ "\\u007F",
2636
+ "\\u0080",
2637
+ "\\u0081",
2638
+ "\\u0082",
2639
+ "\\u0083",
2640
+ "\\u0084",
2641
+ "\\u0085",
2642
+ "\\u0086",
2643
+ "\\u0087",
2644
+ "\\u0088",
2645
+ "\\u0089",
2646
+ "\\u008A",
2647
+ "\\u008B",
2648
+ "\\u008C",
2649
+ "\\u008D",
2650
+ "\\u008E",
2651
+ "\\u008F",
2652
+ "\\u0090",
2653
+ "\\u0091",
2654
+ "\\u0092",
2655
+ "\\u0093",
2656
+ "\\u0094",
2657
+ "\\u0095",
2658
+ "\\u0096",
2659
+ "\\u0097",
2660
+ "\\u0098",
2661
+ "\\u0099",
2662
+ "\\u009A",
2663
+ "\\u009B",
2664
+ "\\u009C",
2665
+ "\\u009D",
2666
+ "\\u009E",
2667
+ "\\u009F"
2668
+ ];
2669
+ const BREAK = Object.freeze({});
2670
+ function visit(root, visitor, visitorKeys = QueryDocumentKeys) {
2671
+ const enterLeaveMap = /* @__PURE__ */ new Map();
2672
+ for (const kind of Object.values(Kind)) {
2673
+ enterLeaveMap.set(kind, getEnterLeaveForKind(visitor, kind));
2674
+ }
2675
+ let stack = void 0;
2676
+ let inArray = Array.isArray(root);
2677
+ let keys = [root];
2678
+ let index = -1;
2679
+ let edits = [];
2680
+ let node = root;
2681
+ let key = void 0;
2682
+ let parent = void 0;
2683
+ const path = [];
2684
+ const ancestors = [];
2685
+ do {
2686
+ index++;
2687
+ const isLeaving = index === keys.length;
2688
+ const isEdited = isLeaving && edits.length !== 0;
2689
+ if (isLeaving) {
2690
+ key = ancestors.length === 0 ? void 0 : path[path.length - 1];
2691
+ node = parent;
2692
+ parent = ancestors.pop();
2693
+ if (isEdited) {
2694
+ if (inArray) {
2695
+ node = node.slice();
2696
+ let editOffset = 0;
2697
+ for (const [editKey, editValue] of edits) {
2698
+ const arrayKey = editKey - editOffset;
2699
+ if (editValue === null) {
2700
+ node.splice(arrayKey, 1);
2701
+ editOffset++;
2702
+ } else {
2703
+ node[arrayKey] = editValue;
2704
+ }
2705
+ }
2706
+ } else {
2707
+ node = { ...node };
2708
+ for (const [editKey, editValue] of edits) {
2709
+ node[editKey] = editValue;
2710
+ }
2711
+ }
2712
+ }
2713
+ index = stack.index;
2714
+ keys = stack.keys;
2715
+ edits = stack.edits;
2716
+ inArray = stack.inArray;
2717
+ stack = stack.prev;
2718
+ } else if (parent) {
2719
+ key = inArray ? index : keys[index];
2720
+ node = parent[key];
2721
+ if (node === null || node === void 0) {
2722
+ continue;
2723
+ }
2724
+ path.push(key);
2725
+ }
2726
+ let result;
2727
+ if (!Array.isArray(node)) {
2728
+ var _enterLeaveMap$get, _enterLeaveMap$get2;
2729
+ isNode(node) || devAssert(false, `Invalid AST Node: ${inspect(node)}.`);
2730
+ const visitFn = isLeaving ? (_enterLeaveMap$get = enterLeaveMap.get(node.kind)) === null || _enterLeaveMap$get === void 0 ? void 0 : _enterLeaveMap$get.leave : (_enterLeaveMap$get2 = enterLeaveMap.get(node.kind)) === null || _enterLeaveMap$get2 === void 0 ? void 0 : _enterLeaveMap$get2.enter;
2731
+ result = visitFn === null || visitFn === void 0 ? void 0 : visitFn.call(visitor, node, key, parent, path, ancestors);
2732
+ if (result === BREAK) {
2733
+ break;
2734
+ }
2735
+ if (result === false) {
2736
+ if (!isLeaving) {
2737
+ path.pop();
2738
+ continue;
2739
+ }
2740
+ } else if (result !== void 0) {
2741
+ edits.push([key, result]);
2742
+ if (!isLeaving) {
2743
+ if (isNode(result)) {
2744
+ node = result;
2745
+ } else {
2746
+ path.pop();
2747
+ continue;
2748
+ }
2749
+ }
2750
+ }
2751
+ }
2752
+ if (result === void 0 && isEdited) {
2753
+ edits.push([key, node]);
2754
+ }
2755
+ if (isLeaving) {
2756
+ path.pop();
2757
+ } else {
2758
+ var _node$kind;
2759
+ stack = {
2760
+ inArray,
2761
+ index,
2762
+ keys,
2763
+ edits,
2764
+ prev: stack
2765
+ };
2766
+ inArray = Array.isArray(node);
2767
+ keys = inArray ? node : (_node$kind = visitorKeys[node.kind]) !== null && _node$kind !== void 0 ? _node$kind : [];
2768
+ index = -1;
2769
+ edits = [];
2770
+ if (parent) {
2771
+ ancestors.push(parent);
2772
+ }
2773
+ parent = node;
2774
+ }
2775
+ } while (stack !== void 0);
2776
+ if (edits.length !== 0) {
2777
+ return edits[edits.length - 1][1];
2778
+ }
2779
+ return root;
2780
+ }
2781
+ function getEnterLeaveForKind(visitor, kind) {
2782
+ const kindVisitor = visitor[kind];
2783
+ if (typeof kindVisitor === "object") {
2784
+ return kindVisitor;
2785
+ } else if (typeof kindVisitor === "function") {
2786
+ return {
2787
+ enter: kindVisitor,
2788
+ leave: void 0
2789
+ };
2790
+ }
2791
+ return {
2792
+ enter: visitor.enter,
2793
+ leave: visitor.leave
2794
+ };
2795
+ }
2796
+ function print(ast) {
2797
+ return visit(ast, printDocASTReducer);
2798
+ }
2799
+ const MAX_LINE_LENGTH = 80;
2800
+ const printDocASTReducer = {
2801
+ Name: {
2802
+ leave: (node) => node.value
2803
+ },
2804
+ Variable: {
2805
+ leave: (node) => "$" + node.name
2806
+ },
2807
+ // Document
2808
+ Document: {
2809
+ leave: (node) => join(node.definitions, "\n\n")
2810
+ },
2811
+ OperationDefinition: {
2812
+ leave(node) {
2813
+ const varDefs = wrap("(", join(node.variableDefinitions, ", "), ")");
2814
+ const prefix = join(
2815
+ [
2816
+ node.operation,
2817
+ join([node.name, varDefs]),
2818
+ join(node.directives, " ")
2819
+ ],
2820
+ " "
2821
+ );
2822
+ return (prefix === "query" ? "" : prefix + " ") + node.selectionSet;
2823
+ }
2824
+ },
2825
+ VariableDefinition: {
2826
+ leave: ({ variable, type, defaultValue, directives }) => variable + ": " + type + wrap(" = ", defaultValue) + wrap(" ", join(directives, " "))
2827
+ },
2828
+ SelectionSet: {
2829
+ leave: ({ selections }) => block(selections)
2830
+ },
2831
+ Field: {
2832
+ leave({ alias, name, arguments: args, directives, selectionSet }) {
2833
+ const prefix = wrap("", alias, ": ") + name;
2834
+ let argsLine = prefix + wrap("(", join(args, ", "), ")");
2835
+ if (argsLine.length > MAX_LINE_LENGTH) {
2836
+ argsLine = prefix + wrap("(\n", indent(join(args, "\n")), "\n)");
2837
+ }
2838
+ return join([argsLine, join(directives, " "), selectionSet], " ");
2839
+ }
2840
+ },
2841
+ Argument: {
2842
+ leave: ({ name, value }) => name + ": " + value
2843
+ },
2844
+ // Fragments
2845
+ FragmentSpread: {
2846
+ leave: ({ name, directives }) => "..." + name + wrap(" ", join(directives, " "))
2847
+ },
2848
+ InlineFragment: {
2849
+ leave: ({ typeCondition, directives, selectionSet }) => join(
2850
+ [
2851
+ "...",
2852
+ wrap("on ", typeCondition),
2853
+ join(directives, " "),
2854
+ selectionSet
2855
+ ],
2856
+ " "
2857
+ )
2858
+ },
2859
+ FragmentDefinition: {
2860
+ leave: ({ name, typeCondition, variableDefinitions, directives, selectionSet }) => (
2861
+ // or removed in the future.
2862
+ `fragment ${name}${wrap("(", join(variableDefinitions, ", "), ")")} on ${typeCondition} ${wrap("", join(directives, " "), " ")}` + selectionSet
2863
+ )
2864
+ },
2865
+ // Value
2866
+ IntValue: {
2867
+ leave: ({ value }) => value
2868
+ },
2869
+ FloatValue: {
2870
+ leave: ({ value }) => value
2871
+ },
2872
+ StringValue: {
2873
+ leave: ({ value, block: isBlockString }) => isBlockString ? printBlockString(value) : printString(value)
2874
+ },
2875
+ BooleanValue: {
2876
+ leave: ({ value }) => value ? "true" : "false"
2877
+ },
2878
+ NullValue: {
2879
+ leave: () => "null"
2880
+ },
2881
+ EnumValue: {
2882
+ leave: ({ value }) => value
2883
+ },
2884
+ ListValue: {
2885
+ leave: ({ values }) => "[" + join(values, ", ") + "]"
2886
+ },
2887
+ ObjectValue: {
2888
+ leave: ({ fields }) => "{" + join(fields, ", ") + "}"
2889
+ },
2890
+ ObjectField: {
2891
+ leave: ({ name, value }) => name + ": " + value
2892
+ },
2893
+ // Directive
2894
+ Directive: {
2895
+ leave: ({ name, arguments: args }) => "@" + name + wrap("(", join(args, ", "), ")")
2896
+ },
2897
+ // Type
2898
+ NamedType: {
2899
+ leave: ({ name }) => name
2900
+ },
2901
+ ListType: {
2902
+ leave: ({ type }) => "[" + type + "]"
2903
+ },
2904
+ NonNullType: {
2905
+ leave: ({ type }) => type + "!"
2906
+ },
2907
+ // Type System Definitions
2908
+ SchemaDefinition: {
2909
+ leave: ({ description, directives, operationTypes }) => wrap("", description, "\n") + join(["schema", join(directives, " "), block(operationTypes)], " ")
2910
+ },
2911
+ OperationTypeDefinition: {
2912
+ leave: ({ operation, type }) => operation + ": " + type
2913
+ },
2914
+ ScalarTypeDefinition: {
2915
+ leave: ({ description, name, directives }) => wrap("", description, "\n") + join(["scalar", name, join(directives, " ")], " ")
2916
+ },
2917
+ ObjectTypeDefinition: {
2918
+ leave: ({ description, name, interfaces, directives, fields }) => wrap("", description, "\n") + join(
2919
+ [
2920
+ "type",
2921
+ name,
2922
+ wrap("implements ", join(interfaces, " & ")),
2923
+ join(directives, " "),
2924
+ block(fields)
2925
+ ],
2926
+ " "
2927
+ )
2928
+ },
2929
+ FieldDefinition: {
2930
+ leave: ({ description, name, arguments: args, type, directives }) => wrap("", description, "\n") + name + (hasMultilineItems(args) ? wrap("(\n", indent(join(args, "\n")), "\n)") : wrap("(", join(args, ", "), ")")) + ": " + type + wrap(" ", join(directives, " "))
2931
+ },
2932
+ InputValueDefinition: {
2933
+ leave: ({ description, name, type, defaultValue, directives }) => wrap("", description, "\n") + join(
2934
+ [name + ": " + type, wrap("= ", defaultValue), join(directives, " ")],
2935
+ " "
2936
+ )
2937
+ },
2938
+ InterfaceTypeDefinition: {
2939
+ leave: ({ description, name, interfaces, directives, fields }) => wrap("", description, "\n") + join(
2940
+ [
2941
+ "interface",
2942
+ name,
2943
+ wrap("implements ", join(interfaces, " & ")),
2944
+ join(directives, " "),
2945
+ block(fields)
2946
+ ],
2947
+ " "
2948
+ )
2949
+ },
2950
+ UnionTypeDefinition: {
2951
+ leave: ({ description, name, directives, types }) => wrap("", description, "\n") + join(
2952
+ ["union", name, join(directives, " "), wrap("= ", join(types, " | "))],
2953
+ " "
2954
+ )
2955
+ },
2956
+ EnumTypeDefinition: {
2957
+ leave: ({ description, name, directives, values }) => wrap("", description, "\n") + join(["enum", name, join(directives, " "), block(values)], " ")
2958
+ },
2959
+ EnumValueDefinition: {
2960
+ leave: ({ description, name, directives }) => wrap("", description, "\n") + join([name, join(directives, " ")], " ")
2961
+ },
2962
+ InputObjectTypeDefinition: {
2963
+ leave: ({ description, name, directives, fields }) => wrap("", description, "\n") + join(["input", name, join(directives, " "), block(fields)], " ")
2964
+ },
2965
+ DirectiveDefinition: {
2966
+ leave: ({ description, name, arguments: args, repeatable, locations }) => wrap("", description, "\n") + "directive @" + name + (hasMultilineItems(args) ? wrap("(\n", indent(join(args, "\n")), "\n)") : wrap("(", join(args, ", "), ")")) + (repeatable ? " repeatable" : "") + " on " + join(locations, " | ")
2967
+ },
2968
+ SchemaExtension: {
2969
+ leave: ({ directives, operationTypes }) => join(
2970
+ ["extend schema", join(directives, " "), block(operationTypes)],
2971
+ " "
2972
+ )
2973
+ },
2974
+ ScalarTypeExtension: {
2975
+ leave: ({ name, directives }) => join(["extend scalar", name, join(directives, " ")], " ")
2976
+ },
2977
+ ObjectTypeExtension: {
2978
+ leave: ({ name, interfaces, directives, fields }) => join(
2979
+ [
2980
+ "extend type",
2981
+ name,
2982
+ wrap("implements ", join(interfaces, " & ")),
2983
+ join(directives, " "),
2984
+ block(fields)
2985
+ ],
2986
+ " "
2987
+ )
2988
+ },
2989
+ InterfaceTypeExtension: {
2990
+ leave: ({ name, interfaces, directives, fields }) => join(
2991
+ [
2992
+ "extend interface",
2993
+ name,
2994
+ wrap("implements ", join(interfaces, " & ")),
2995
+ join(directives, " "),
2996
+ block(fields)
2997
+ ],
2998
+ " "
2999
+ )
3000
+ },
3001
+ UnionTypeExtension: {
3002
+ leave: ({ name, directives, types }) => join(
3003
+ [
3004
+ "extend union",
3005
+ name,
3006
+ join(directives, " "),
3007
+ wrap("= ", join(types, " | "))
3008
+ ],
3009
+ " "
3010
+ )
3011
+ },
3012
+ EnumTypeExtension: {
3013
+ leave: ({ name, directives, values }) => join(["extend enum", name, join(directives, " "), block(values)], " ")
3014
+ },
3015
+ InputObjectTypeExtension: {
3016
+ leave: ({ name, directives, fields }) => join(["extend input", name, join(directives, " "), block(fields)], " ")
3017
+ }
3018
+ };
3019
+ function join(maybeArray, separator = "") {
3020
+ var _maybeArray$filter$jo;
3021
+ return (_maybeArray$filter$jo = maybeArray === null || maybeArray === void 0 ? void 0 : maybeArray.filter((x) => x).join(separator)) !== null && _maybeArray$filter$jo !== void 0 ? _maybeArray$filter$jo : "";
3022
+ }
3023
+ function block(array) {
3024
+ return wrap("{\n", indent(join(array, "\n")), "\n}");
3025
+ }
3026
+ function wrap(start, maybeString, end = "") {
3027
+ return maybeString != null && maybeString !== "" ? start + maybeString + end : "";
3028
+ }
3029
+ function indent(str) {
3030
+ return wrap(" ", str.replace(/\n/g, "\n "));
3031
+ }
3032
+ function hasMultilineItems(maybeArray) {
3033
+ var _maybeArray$some;
3034
+ return (_maybeArray$some = maybeArray === null || maybeArray === void 0 ? void 0 : maybeArray.some((str) => str.includes("\n"))) !== null && _maybeArray$some !== void 0 ? _maybeArray$some : false;
3035
+ }
2491
3036
  function stripIgnoredCharacters(source) {
2492
3037
  const sourceObj = isSource(source) ? source : new Source(source);
2493
3038
  const body = sourceObj.body;
@@ -2624,6 +3169,7 @@ export {
2624
3169
  Kind,
2625
3170
  astResolver,
2626
3171
  gql,
2627
- parse
3172
+ parse,
3173
+ print
2628
3174
  };
2629
3175
  //# sourceMappingURL=index.js.map