@graphiql/plugin-query-builder 1.0.0-beta.0 → 1.0.0-beta.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/LICENSE +21 -0
- package/dist/components/arg-input/arg-input-by-type.js +441 -444
- package/dist/components/arg-input/arg-input-by-type.js.map +1 -1
- package/dist/components/arg-input/enum-arg-control.js +49 -52
- package/dist/components/arg-input/enum-arg-control.js.map +1 -1
- package/dist/components/arg-input/index.js +44 -36
- package/dist/components/arg-input/index.js.map +1 -1
- package/dist/components/arg-input/scalar-arg-control.js +58 -63
- package/dist/components/arg-input/scalar-arg-control.js.map +1 -1
- package/dist/components/field-row.js +212 -197
- package/dist/components/field-row.js.map +1 -1
- package/dist/components/field-tree-context.js +23 -27
- package/dist/components/field-tree-context.js.map +1 -1
- package/dist/components/field-tree-node.js +128 -105
- package/dist/components/field-tree-node.js.map +1 -1
- package/dist/components/field-tree.js +178 -199
- package/dist/components/field-tree.js.map +1 -1
- package/dist/components/fragment-editor.js +157 -151
- package/dist/components/fragment-editor.js.map +1 -1
- package/dist/components/fragment-section.js +215 -203
- package/dist/components/fragment-section.js.map +1 -1
- package/dist/components/query-builder.js +205 -181
- package/dist/components/query-builder.js.map +1 -1
- package/dist/components/type-condition-selector.js +417 -462
- package/dist/components/type-condition-selector.js.map +1 -1
- package/dist/components/use-cursor-path.js +69 -70
- package/dist/components/use-cursor-path.js.map +1 -1
- package/dist/components/use-cursor-reveal.js +83 -89
- package/dist/components/use-cursor-reveal.js.map +1 -1
- package/dist/components/use-working-document.js +432 -527
- package/dist/components/use-working-document.js.map +1 -1
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/lib/arg-value.js +132 -139
- package/dist/lib/arg-value.js.map +1 -1
- package/dist/lib/arguments.js +54 -55
- package/dist/lib/arguments.js.map +1 -1
- package/dist/lib/ast-path.js +266 -291
- package/dist/lib/ast-path.js.map +1 -1
- package/dist/lib/field-list-view.js +33 -43
- package/dist/lib/field-list-view.js.map +1 -1
- package/dist/lib/field-selection.js +63 -67
- package/dist/lib/field-selection.js.map +1 -1
- package/dist/lib/fragments.js +166 -152
- package/dist/lib/fragments.js.map +1 -1
- package/dist/lib/inline-fragments.js +64 -62
- package/dist/lib/inline-fragments.js.map +1 -1
- package/dist/lib/schema-walk.js +141 -158
- package/dist/lib/schema-walk.js.map +1 -1
- package/dist/lib/variables.js +96 -90
- package/dist/lib/variables.js.map +1 -1
- package/dist/style.css +4 -22
- package/package.json +21 -18
package/dist/lib/arguments.js
CHANGED
|
@@ -1,62 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { mapDefinition, setArgInSelectionSet, findDefinition, findNodeAtPath } from "./ast-path.js";
|
|
1
|
+
import { findDefinition, findNodeAtPath, mapDefinition, setArgInSelectionSet } from "./ast-path.js";
|
|
3
2
|
import { valueNodeToArgValue } from "./arg-value.js";
|
|
3
|
+
import { Kind } from "graphql";
|
|
4
|
+
//#region src/lib/arguments.ts
|
|
5
|
+
/**
|
|
6
|
+
* Returns a map of argument name → variable name for arguments at `path` that
|
|
7
|
+
* are currently bound to a variable (i.e., the argument value is a
|
|
8
|
+
* `Variable` node). Only includes args that are variable-bound; literal-valued
|
|
9
|
+
* args are omitted.
|
|
10
|
+
*/
|
|
4
11
|
function getFieldArgVariables(doc, path, target) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (!node) {
|
|
14
|
-
return {};
|
|
15
|
-
}
|
|
16
|
-
const result = {};
|
|
17
|
-
for (const arg of node.arguments ?? []) {
|
|
18
|
-
if (arg.value.kind === Kind.VARIABLE) {
|
|
19
|
-
result[arg.name.value] = arg.value.name.value;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return result;
|
|
12
|
+
if (path.length === 0) return {};
|
|
13
|
+
const definition = findDefinition(doc, target);
|
|
14
|
+
if (!definition) return {};
|
|
15
|
+
const node = findNodeAtPath(definition.selectionSet, path);
|
|
16
|
+
if (!node) return {};
|
|
17
|
+
const result = {};
|
|
18
|
+
for (const arg of node.arguments ?? []) if (arg.value.kind === Kind.VARIABLE) result[arg.name.value] = arg.value.name.value;
|
|
19
|
+
return result;
|
|
23
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns a map of argument name → `ArgValue` for the field at `path`
|
|
23
|
+
* in the definition addressed by `target` (an operation or a named fragment)
|
|
24
|
+
* of `doc`. Values are extracted from the AST and converted to `ArgValue`
|
|
25
|
+
* (leaves become strings; lists and input objects become arrays and plain
|
|
26
|
+
* objects). Arguments not present in the doc are omitted from the returned
|
|
27
|
+
* object.
|
|
28
|
+
*/
|
|
24
29
|
function getFieldArgValues(doc, path, target) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (!node) {
|
|
34
|
-
return {};
|
|
35
|
-
}
|
|
36
|
-
const result = {};
|
|
37
|
-
for (const arg of node.arguments ?? []) {
|
|
38
|
-
result[arg.name.value] = valueNodeToArgValue(arg.value);
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
30
|
+
if (path.length === 0) return {};
|
|
31
|
+
const definition = findDefinition(doc, target);
|
|
32
|
+
if (!definition) return {};
|
|
33
|
+
const node = findNodeAtPath(definition.selectionSet, path);
|
|
34
|
+
if (!node) return {};
|
|
35
|
+
const result = {};
|
|
36
|
+
for (const arg of node.arguments ?? []) result[arg.name.value] = valueNodeToArgValue(arg.value);
|
|
37
|
+
return result;
|
|
41
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Sets or removes a named argument on the field located at `path` within the
|
|
41
|
+
* definition addressed by `target` (an operation or a named fragment) of `doc`.
|
|
42
|
+
* When `value` is `undefined` the argument is removed; otherwise it is added
|
|
43
|
+
* or updated in place.
|
|
44
|
+
*
|
|
45
|
+
* Returns a new `DocumentNode`; does not mutate `doc`.
|
|
46
|
+
*/
|
|
42
47
|
function setFieldArgument(doc, path, argName, value, target) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
...definition,
|
|
53
|
-
selectionSet: newSelectionSet
|
|
54
|
-
};
|
|
55
|
-
});
|
|
48
|
+
if (path.length === 0) return doc;
|
|
49
|
+
return mapDefinition(doc, target, (definition) => {
|
|
50
|
+
const newSelectionSet = setArgInSelectionSet(definition.selectionSet, path, argName, value);
|
|
51
|
+
if (newSelectionSet === definition.selectionSet) return definition;
|
|
52
|
+
return {
|
|
53
|
+
...definition,
|
|
54
|
+
selectionSet: newSelectionSet
|
|
55
|
+
};
|
|
56
|
+
});
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
//# sourceMappingURL=arguments.js.map
|
|
58
|
+
//#endregion
|
|
59
|
+
export { getFieldArgValues, getFieldArgVariables, setFieldArgument };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=arguments.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arguments.js","sources":["../../src/lib/arguments.ts"],"sourcesContent":["import {\n Kind,\n type DocumentNode,\n type FieldNode,\n type ValueNode,\n} from 'graphql';\n\nimport {\n findNodeAtPath,\n findDefinition,\n mapDefinition,\n setArgInSelectionSet,\n type DefinitionTarget,\n type PathSegment,\n} from './ast-path';\nimport { type ArgValue, valueNodeToArgValue } from './arg-value';\n\n/**\n * Returns a map of argument name → variable name for arguments at `path` that\n * are currently bound to a variable (i.e., the argument value is a\n * `Variable` node). Only includes args that are variable-bound; literal-valued\n * args are omitted.\n */\nexport function getFieldArgVariables(\n doc: DocumentNode,\n path: PathSegment[],\n target: DefinitionTarget,\n): Record<string, string> {\n if (path.length === 0) {\n return {};\n }\n\n const definition = findDefinition(doc, target);\n if (!definition) {\n return {};\n }\n\n const node = findNodeAtPath(definition.selectionSet, path);\n if (!node) {\n return {};\n }\n\n const result: Record<string, string> = {};\n for (const arg of (node as FieldNode).arguments ?? []) {\n if (arg.value.kind === Kind.VARIABLE) {\n result[arg.name.value] = arg.value.name.value;\n }\n }\n return result;\n}\n\n/**\n * Returns a map of argument name → `ArgValue` for the field at `path`\n * in the definition addressed by `target` (an operation or a named fragment)\n * of `doc`. Values are extracted from the AST and converted to `ArgValue`\n * (leaves become strings; lists and input objects become arrays and plain\n * objects). Arguments not present in the doc are omitted from the returned\n * object.\n */\nexport function getFieldArgValues(\n doc: DocumentNode,\n path: PathSegment[],\n target: DefinitionTarget,\n): Record<string, ArgValue> {\n if (path.length === 0) {\n return {};\n }\n\n const definition = findDefinition(doc, target);\n if (!definition) {\n return {};\n }\n\n const node = findNodeAtPath(definition.selectionSet, path);\n if (!node) {\n return {};\n }\n\n const result: Record<string, ArgValue> = {};\n for (const arg of (node as FieldNode).arguments ?? []) {\n result[arg.name.value] = valueNodeToArgValue(arg.value);\n }\n return result;\n}\n\n/**\n * Sets or removes a named argument on the field located at `path` within the\n * definition addressed by `target` (an operation or a named fragment) of `doc`.\n * When `value` is `undefined` the argument is removed; otherwise it is added\n * or updated in place.\n *\n * Returns a new `DocumentNode`; does not mutate `doc`.\n */\nexport function setFieldArgument(\n doc: DocumentNode,\n path: PathSegment[],\n argName: string,\n value: ValueNode | undefined,\n target: DefinitionTarget,\n): DocumentNode {\n if (path.length === 0) {\n return doc;\n }\n\n return mapDefinition(doc, target, definition => {\n const newSelectionSet = setArgInSelectionSet(\n definition.selectionSet,\n path,\n argName,\n value,\n );\n if (newSelectionSet === definition.selectionSet) {\n return definition;\n }\n return { ...definition, selectionSet: newSelectionSet };\n });\n}\n"],"
|
|
1
|
+
{"version":3,"file":"arguments.js","names":["Kind","DocumentNode","FieldNode","ValueNode","findNodeAtPath","findDefinition","mapDefinition","setArgInSelectionSet","DefinitionTarget","PathSegment","ArgValue","valueNodeToArgValue","getFieldArgVariables","doc","path","target","Record","length","definition","node","selectionSet","result","arg","arguments","value","kind","VARIABLE","name","getFieldArgValues","setFieldArgument","argName","newSelectionSet"],"sources":["../../src/lib/arguments.ts"],"sourcesContent":["import {\n Kind,\n type DocumentNode,\n type FieldNode,\n type ValueNode,\n} from 'graphql';\n\nimport {\n findNodeAtPath,\n findDefinition,\n mapDefinition,\n setArgInSelectionSet,\n type DefinitionTarget,\n type PathSegment,\n} from './ast-path';\nimport { type ArgValue, valueNodeToArgValue } from './arg-value';\n\n/**\n * Returns a map of argument name → variable name for arguments at `path` that\n * are currently bound to a variable (i.e., the argument value is a\n * `Variable` node). Only includes args that are variable-bound; literal-valued\n * args are omitted.\n */\nexport function getFieldArgVariables(\n doc: DocumentNode,\n path: PathSegment[],\n target: DefinitionTarget,\n): Record<string, string> {\n if (path.length === 0) {\n return {};\n }\n\n const definition = findDefinition(doc, target);\n if (!definition) {\n return {};\n }\n\n const node = findNodeAtPath(definition.selectionSet, path);\n if (!node) {\n return {};\n }\n\n const result: Record<string, string> = {};\n for (const arg of (node as FieldNode).arguments ?? []) {\n if (arg.value.kind === Kind.VARIABLE) {\n result[arg.name.value] = arg.value.name.value;\n }\n }\n return result;\n}\n\n/**\n * Returns a map of argument name → `ArgValue` for the field at `path`\n * in the definition addressed by `target` (an operation or a named fragment)\n * of `doc`. Values are extracted from the AST and converted to `ArgValue`\n * (leaves become strings; lists and input objects become arrays and plain\n * objects). Arguments not present in the doc are omitted from the returned\n * object.\n */\nexport function getFieldArgValues(\n doc: DocumentNode,\n path: PathSegment[],\n target: DefinitionTarget,\n): Record<string, ArgValue> {\n if (path.length === 0) {\n return {};\n }\n\n const definition = findDefinition(doc, target);\n if (!definition) {\n return {};\n }\n\n const node = findNodeAtPath(definition.selectionSet, path);\n if (!node) {\n return {};\n }\n\n const result: Record<string, ArgValue> = {};\n for (const arg of (node as FieldNode).arguments ?? []) {\n result[arg.name.value] = valueNodeToArgValue(arg.value);\n }\n return result;\n}\n\n/**\n * Sets or removes a named argument on the field located at `path` within the\n * definition addressed by `target` (an operation or a named fragment) of `doc`.\n * When `value` is `undefined` the argument is removed; otherwise it is added\n * or updated in place.\n *\n * Returns a new `DocumentNode`; does not mutate `doc`.\n */\nexport function setFieldArgument(\n doc: DocumentNode,\n path: PathSegment[],\n argName: string,\n value: ValueNode | undefined,\n target: DefinitionTarget,\n): DocumentNode {\n if (path.length === 0) {\n return doc;\n }\n\n return mapDefinition(doc, target, definition => {\n const newSelectionSet = setArgInSelectionSet(\n definition.selectionSet,\n path,\n argName,\n value,\n );\n if (newSelectionSet === definition.selectionSet) {\n return definition;\n }\n return { ...definition, selectionSet: newSelectionSet };\n });\n}\n"],"mappings":";;;;;;;;;;AAuBA,SAAgBY,qBACdC,KACAC,MACAC,QACwB;CACxB,IAAID,KAAKG,WAAW,GAClB,OAAO,CAAC;CAGV,MAAMC,aAAab,eAAeQ,KAAKE,MAAM;CAC7C,IAAI,CAACG,YACH,OAAO,CAAC;CAGV,MAAMC,OAAOf,eAAec,WAAWE,cAAcN,IAAI;CACzD,IAAI,CAACK,MACH,OAAO,CAAC;CAGV,MAAME,SAAiC,CAAC;CACxC,KAAK,MAAMC,OAAQH,KAAmBI,aAAa,CAAA,GACjD,IAAID,IAAIE,MAAMC,SAASzB,KAAK0B,UAC1BL,OAAOC,IAAIK,KAAKH,SAASF,IAAIE,MAAMG,KAAKH;CAG5C,OAAOH;AACT;;;;;;;;;AAUA,SAAgBO,kBACdf,KACAC,MACAC,QAC0B;CAC1B,IAAID,KAAKG,WAAW,GAClB,OAAO,CAAC;CAGV,MAAMC,aAAab,eAAeQ,KAAKE,MAAM;CAC7C,IAAI,CAACG,YACH,OAAO,CAAC;CAGV,MAAMC,OAAOf,eAAec,WAAWE,cAAcN,IAAI;CACzD,IAAI,CAACK,MACH,OAAO,CAAC;CAGV,MAAME,SAAmC,CAAC;CAC1C,KAAK,MAAMC,OAAQH,KAAmBI,aAAa,CAAA,GACjDF,OAAOC,IAAIK,KAAKH,SAASb,oBAAoBW,IAAIE,KAAK;CAExD,OAAOH;AACT;;;;;;;;;AAUA,SAAgBQ,iBACdhB,KACAC,MACAgB,SACAN,OACAT,QACc;CACd,IAAID,KAAKG,WAAW,GAClB,OAAOJ;CAGT,OAAOP,cAAcO,KAAKE,SAAQG,eAAc;EAC9C,MAAMa,kBAAkBxB,qBACtBW,WAAWE,cACXN,MACAgB,SACAN,KACF;EACA,IAAIO,oBAAoBb,WAAWE,cACjC,OAAOF;EAET,OAAO;GAAE,GAAGA;GAAYE,cAAcW;EAAgB;CACxD,CAAC;AACH"}
|