@graphiql/plugin-query-builder 1.0.1 → 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/components/arg-input/arg-input-by-type.js +3 -3
- package/dist/components/arg-input/arg-input-by-type.js.map +1 -1
- package/dist/components/arg-input/enum-arg-control.js +11 -6
- package/dist/components/arg-input/enum-arg-control.js.map +1 -1
- package/dist/components/arg-input/index.js +1 -1
- package/dist/components/arg-input/index.js.map +1 -1
- package/dist/components/arg-input/scalar-arg-control.js +12 -7
- package/dist/components/arg-input/scalar-arg-control.js.map +1 -1
- package/dist/components/field-row.js +2 -2
- package/dist/components/field-row.js.map +1 -1
- package/dist/components/field-tree-context.js.map +1 -1
- package/dist/components/field-tree-node.js +2 -2
- package/dist/components/field-tree-node.js.map +1 -1
- package/dist/components/field-tree.js +13 -9
- package/dist/components/field-tree.js.map +1 -1
- package/dist/components/fragment-editor.js +3 -3
- package/dist/components/fragment-editor.js.map +1 -1
- package/dist/components/fragment-section.js +14 -10
- package/dist/components/fragment-section.js.map +1 -1
- package/dist/components/query-builder.js +6 -6
- package/dist/components/query-builder.js.map +1 -1
- package/dist/components/type-condition-selector.js +4 -4
- package/dist/components/type-condition-selector.js.map +1 -1
- package/dist/components/use-cursor-path.js +2 -2
- package/dist/components/use-cursor-path.js.map +1 -1
- package/dist/components/use-cursor-reveal.js +1 -1
- package/dist/components/use-cursor-reveal.js.map +1 -1
- package/dist/components/use-working-document.js +4 -4
- package/dist/components/use-working-document.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/arg-value.js.map +1 -1
- package/dist/lib/arguments.js +1 -1
- package/dist/lib/arguments.js.map +1 -1
- package/dist/lib/ast-path.js.map +1 -1
- package/dist/lib/field-list-view.js.map +1 -1
- package/dist/lib/field-selection.js +1 -1
- package/dist/lib/field-selection.js.map +1 -1
- package/dist/lib/fragments.js +1 -1
- package/dist/lib/fragments.js.map +1 -1
- package/dist/lib/inline-fragments.js +1 -1
- package/dist/lib/inline-fragments.js.map +1 -1
- package/dist/lib/schema-walk.js +1 -1
- package/dist/lib/schema-walk.js.map +1 -1
- package/dist/lib/variables.js +1 -1
- package/dist/lib/variables.js.map +1 -1
- package/dist/style.css +14 -62
- package/package.json +13 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-walk.js","names":["Kind","OperationTypeNode","isInterfaceType","isObjectType","visit","DocumentNode","FieldNode","GraphQLArgument","GraphQLNamedType","GraphQLSchema","InlineFragmentNode","SelectionNode","getNamedType","fieldSegment","inlineFragmentSegment","DefinitionTarget","PathSegment","readVariables","text","Record","trim","parsed","JSON","parse","Array","isArray","pathWithinSelections","rootSelections","offset","path","selections","selection","find","s","kind","FIELD","INLINE_FRAGMENT","loc","start","end","push","name","value","typeName","typeCondition","selectionSet","fieldPathAtOffset","doc","op","definitions","d","OPERATION_DEFINITION","cursorContextAtOffset","target","def","FRAGMENT_DEFINITION","undefined","findOperationDefinition","operationName","byName","selectionMatchesSegment","segment","extractRawArgValue","argName","i","length","seg","node","argNode","arguments","a","v","STRING","INT","FLOAT","BOOLEAN","String","ENUM","countSelectedFields","count","Field","resolveSchemaArg","schema","activeOpKind","rootType","getRootType","QUERY","getQueryType","resolveSchemaArgFromRoot","currentType","targetField","args","condition","getType","fields","getFields","f","type","named","Parameters","resolveFieldNamedType","result"],"sources":["../../src/lib/schema-walk.ts"],"sourcesContent":["import {\n Kind,\n OperationTypeNode,\n isInterfaceType,\n isObjectType,\n visit,\n type DocumentNode,\n type FieldNode,\n type GraphQLArgument,\n type GraphQLNamedType,\n type GraphQLSchema,\n type InlineFragmentNode,\n type SelectionNode,\n getNamedType,\n} from 'graphql';\nimport {\n fieldSegment,\n inlineFragmentSegment,\n type DefinitionTarget,\n type PathSegment,\n} from './ast-path';\n\n/**\n * Safely parse the variables JSON text, returning a plain object or {} on\n * failure. Arrays and non-object values are treated as empty.\n */\nexport function readVariables(\n text: string | null | undefined,\n): Record<string, unknown> {\n if (!text || !text.trim()) {\n return {};\n }\n try {\n const parsed = JSON.parse(text);\n return parsed && typeof parsed === 'object' && !Array.isArray(parsed)\n ? (parsed as Record<string, unknown>)\n : {};\n } catch {\n return {};\n }\n}\n\n/**\n * Returns the tree path of the selection whose source range contains `offset`,\n * walking from the operation that contains the cursor down through nested\n * selection sets. Inline fragments contribute an `inlineFragment` path segment\n * (matching the builder's path model), so the cursor resolves to fields nested\n * inside union/interface type conditions too. Returns `[]` when the cursor\n * isn't inside a field or fragment.\n */\nfunction pathWithinSelections(\n rootSelections: readonly SelectionNode[],\n offset: number,\n): PathSegment[] {\n const path: PathSegment[] = [];\n let selections = rootSelections;\n while (true) {\n const selection = selections.find(\n (s): s is FieldNode | InlineFragmentNode =>\n (s.kind === Kind.FIELD || s.kind === Kind.INLINE_FRAGMENT) &&\n s.loc != null &&\n s.loc.start <= offset &&\n s.loc.end >= offset,\n );\n if (!selection) {\n break;\n }\n if (selection.kind === Kind.FIELD) {\n path.push(fieldSegment(selection.name.value));\n } else {\n const typeName = selection.typeCondition?.name.value;\n if (!typeName) {\n break;\n }\n path.push(inlineFragmentSegment(typeName));\n }\n if (!selection.selectionSet) {\n break;\n }\n selections = selection.selectionSet.selections;\n }\n return path;\n}\n\nexport function fieldPathAtOffset(\n doc: DocumentNode,\n offset: number,\n): PathSegment[] {\n const op = doc.definitions.find(\n d =>\n d.kind === Kind.OPERATION_DEFINITION &&\n d.loc != null &&\n d.loc.start <= offset &&\n d.loc.end >= offset,\n );\n if (!op || op.kind !== Kind.OPERATION_DEFINITION) {\n return [];\n }\n return pathWithinSelections(op.selectionSet.selections, offset);\n}\n\n/**\n * Resolves the definition the cursor sits in — an operation or a named\n * fragment — together with the field path within it. Returns `undefined` when\n * the cursor is not inside any editable definition. Drives cursor-following:\n * moving the editor cursor into a fragment switches the builder to editing it.\n */\nexport function cursorContextAtOffset(\n doc: DocumentNode,\n offset: number,\n): { target: DefinitionTarget; path: PathSegment[] } | undefined {\n const def = doc.definitions.find(\n d =>\n (d.kind === Kind.OPERATION_DEFINITION ||\n d.kind === Kind.FRAGMENT_DEFINITION) &&\n d.loc != null &&\n d.loc.start <= offset &&\n d.loc.end >= offset,\n );\n if (def?.kind === Kind.OPERATION_DEFINITION) {\n return {\n target: { kind: 'operation', name: def.name?.value },\n path: pathWithinSelections(def.selectionSet.selections, offset),\n };\n }\n if (def?.kind === Kind.FRAGMENT_DEFINITION) {\n return {\n target: { kind: 'fragment', name: def.name.value },\n path: pathWithinSelections(def.selectionSet.selections, offset),\n };\n }\n return undefined;\n}\n\n/**\n * Resolves the operation to read from: the one named `operationName` when given\n * and present, otherwise the first operation definition.\n */\nfunction findOperationDefinition(doc: DocumentNode, operationName?: string) {\n const byName = operationName\n ? doc.definitions.find(\n d =>\n d.kind === Kind.OPERATION_DEFINITION &&\n d.name?.value === operationName,\n )\n : undefined;\n const op =\n byName ?? doc.definitions.find(d => d.kind === Kind.OPERATION_DEFINITION);\n return op?.kind === Kind.OPERATION_DEFINITION ? op : undefined;\n}\n\n/**\n * Matches a path segment against a selection, by schema field name or, for an\n * inline-fragment segment, by type condition. Mirrors the document-mutator path\n * model so the cursor/path helpers agree with it.\n */\nfunction selectionMatchesSegment(\n selection: SelectionNode,\n segment: PathSegment,\n): boolean {\n switch (segment.kind) {\n case 'inlineFragment':\n return (\n selection.kind === Kind.INLINE_FRAGMENT &&\n selection.typeCondition?.name.value === segment.typeName\n );\n case 'field':\n return (\n selection.kind === Kind.FIELD && selection.name.value === segment.name\n );\n }\n}\n\n/**\n * Extracts the raw, printable value string for an argument at `path` from the\n * document, e.g. `\"abc\"` for a string or `42` for an int. Returns an empty\n * string when the field, arg, or a value we can render is not found. Walks both\n * field and inline-fragment path segments.\n */\nexport function extractRawArgValue(\n doc: DocumentNode,\n path: PathSegment[],\n argName: string,\n operationName?: string,\n): string {\n const op = findOperationDefinition(doc, operationName);\n if (!op) {\n return '';\n }\n\n let selections: readonly SelectionNode[] = op.selectionSet.selections;\n for (let i = 0; i < path.length; i++) {\n const seg = path[i]!;\n const node = selections.find((s): s is FieldNode | InlineFragmentNode =>\n selectionMatchesSegment(s, seg),\n );\n if (!node) {\n return '';\n }\n if (i === path.length - 1) {\n if (node.kind !== Kind.FIELD) {\n return '';\n }\n const argNode = (node.arguments ?? []).find(\n a => a.name.value === argName,\n );\n if (!argNode) {\n return '';\n }\n const v = argNode.value;\n if (v.kind === Kind.STRING) {\n return `\"${v.value}\"`;\n }\n if (v.kind === Kind.INT || v.kind === Kind.FLOAT) {\n return v.value;\n }\n if (v.kind === Kind.BOOLEAN) {\n return String(v.value);\n }\n if (v.kind === Kind.ENUM) {\n return v.value;\n }\n return '';\n }\n if (!node.selectionSet) {\n return '';\n }\n selections = node.selectionSet.selections;\n }\n return '';\n}\n\n/** Counts the fields selected in the target operation (nested fields included). */\nexport function countSelectedFields(\n doc: DocumentNode,\n operationName?: string,\n): number {\n let count = 0;\n const op = findOperationDefinition(doc, operationName);\n if (op) {\n visit(op, {\n Field() {\n count++;\n },\n });\n }\n return count;\n}\n\n/**\n * Resolves the schema `GraphQLArgument` for the argument `argName` on the field\n * addressed by `path`, walking from the root type for `activeOpKind`. Returns\n * undefined when the field or arg can't be resolved against the schema.\n */\nexport function resolveSchemaArg(\n schema: GraphQLSchema,\n activeOpKind: OperationTypeNode | undefined,\n path: PathSegment[],\n argName: string,\n): GraphQLArgument | undefined {\n const rootType =\n schema.getRootType(activeOpKind ?? OperationTypeNode.QUERY) ??\n schema.getQueryType();\n return resolveSchemaArgFromRoot(schema, rootType ?? undefined, path, argName);\n}\n\n/**\n * Like {@link resolveSchemaArg} but walks from an explicit `rootType` rather\n * than an operation kind, so it resolves args inside a fragment (whose root is\n * its type condition) as well as inside an operation.\n */\nexport function resolveSchemaArgFromRoot(\n schema: GraphQLSchema,\n rootType: GraphQLNamedType | undefined,\n path: PathSegment[],\n argName: string,\n): GraphQLArgument | undefined {\n if (!rootType || path.length === 0) {\n return;\n }\n\n let currentType: GraphQLNamedType = rootType;\n let targetField: { args: readonly GraphQLArgument[] } | undefined;\n for (const seg of path) {\n if (seg.kind === 'inlineFragment') {\n const condition = schema.getType(seg.typeName);\n if (!condition) {\n return;\n }\n currentType = condition;\n targetField = undefined;\n continue;\n }\n if (!(isObjectType(currentType) || isInterfaceType(currentType))) {\n return;\n }\n const fields = currentType.getFields();\n const f = fields[seg.name] as\n | { type: unknown; args: readonly GraphQLArgument[] }\n | undefined;\n if (!f) {\n return;\n }\n targetField = f;\n const named = getNamedType(f.type as Parameters<typeof getNamedType>[0]);\n if (named && (isObjectType(named) || isInterfaceType(named))) {\n currentType = named;\n }\n }\n return targetField?.args.find(a => a.name === argName);\n}\n\n/**\n * Resolves the named type reached by walking `path` from the root type for\n * `activeOpKind`. Field segments descend into the field's type; `inlineFragment`\n * segments switch to that type condition. Returns undefined when a segment\n * doesn't resolve. Used to pick the type condition when extracting a field's\n * selection into a fragment.\n */\nexport function resolveFieldNamedType(\n schema: GraphQLSchema,\n activeOpKind: OperationTypeNode | undefined,\n path: PathSegment[],\n): GraphQLNamedType | undefined {\n const rootType =\n schema.getRootType(activeOpKind ?? OperationTypeNode.QUERY) ??\n schema.getQueryType();\n if (!rootType || path.length === 0) {\n return;\n }\n\n let currentType: GraphQLNamedType = rootType;\n let result: GraphQLNamedType | undefined;\n for (const seg of path) {\n if (seg.kind === 'inlineFragment') {\n const condition = schema.getType(seg.typeName);\n if (!condition) {\n return;\n }\n currentType = condition;\n result = condition;\n continue;\n }\n if (!(isObjectType(currentType) || isInterfaceType(currentType))) {\n return;\n }\n const fields = currentType.getFields();\n const f = fields[seg.name] as { type: unknown } | undefined;\n if (!f) {\n return;\n }\n const named = getNamedType(f.type as Parameters<typeof getNamedType>[0]);\n if (!named) {\n return;\n }\n result = named;\n currentType = named;\n }\n return result;\n}\n"],"mappings":";;;;;;;AA0BA,SAAgBiB,cACdC,MACyB;CACzB,IAAI,CAACA,QAAQ,CAACA,KAAKE,KAAK,G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;EACA,IAAI,EAAErD,aAAasF,WAAW,KAAKvF,gBAAgBuF,WAAW,IAC5D;EAGF,MAAMO,IADSP,YAAYM,UACjBD,CAAAA,CAAO5B,IAAIzB;EAGrB,IAAI,CAACuD,GACH;EAEFN,cAAcM;EACd,MAAME,QAAQtF,aAAaoF,EAAEC,IAA0C;EACvE,IAAIC,UAAU/F,aAAa+F,KAAK,KAAKhG,gBAAgBgG,KAAK,IACxDT,cAAcS;CAElB;CACA,OAAOR,aAAaC,KAAK3D,MAAKsC,MAAKA,EAAE7B,SAASsB,OAAO;AACvD"}
|
|
1
|
+
{"version":3,"file":"schema-walk.js","names":["Kind","OperationTypeNode","isInterfaceType","isObjectType","visit","getNamedType","fieldSegment","inlineFragmentSegment","readVariables","text","trim","parsed","JSON","parse","Array","isArray","pathWithinSelections","rootSelections","offset","path","selections","selection","find","s","kind","FIELD","INLINE_FRAGMENT","loc","start","end","push","name","value","typeName","typeCondition","selectionSet","doc","op","definitions","d","OPERATION_DEFINITION","cursorContextAtOffset","target","def","FRAGMENT_DEFINITION","undefined","findOperationDefinition","operationName","selectionMatchesSegment","segment","extractRawArgValue","argName","i","length","seg","node","argNode","arguments","a","v","STRING","INT","FLOAT","BOOLEAN","String","ENUM","countSelectedFields","count","Field","resolveSchemaArg","schema","activeOpKind","rootType","getRootType","QUERY","getQueryType","resolveSchemaArgFromRoot","currentType","targetField","args","condition","getType","fields","getFields","f","type","named"],"sources":["../../src/lib/schema-walk.ts"],"sourcesContent":["import {\n Kind,\n OperationTypeNode,\n isInterfaceType,\n isObjectType,\n visit,\n type DocumentNode,\n type FieldNode,\n type GraphQLArgument,\n type GraphQLNamedType,\n type GraphQLSchema,\n type InlineFragmentNode,\n type SelectionNode,\n getNamedType,\n} from 'graphql';\nimport {\n fieldSegment,\n inlineFragmentSegment,\n type DefinitionTarget,\n type PathSegment,\n} from './ast-path';\n\n/**\n * Safely parse the variables JSON text, returning a plain object or {} on\n * failure. Arrays and non-object values are treated as empty.\n */\nexport function readVariables(\n text: string | null | undefined,\n): Record<string, unknown> {\n if (!text || !text.trim()) {\n return {};\n }\n try {\n const parsed = JSON.parse(text);\n return parsed && typeof parsed === 'object' && !Array.isArray(parsed)\n ? (parsed as Record<string, unknown>)\n : {};\n } catch {\n return {};\n }\n}\n\n/**\n * Returns the tree path of the selection whose source range contains `offset`,\n * walking from the operation that contains the cursor down through nested\n * selection sets. Inline fragments contribute an `inlineFragment` path segment\n * (matching the builder's path model), so the cursor resolves to fields nested\n * inside union/interface type conditions too. Returns `[]` when the cursor\n * isn't inside a field or fragment.\n */\nfunction pathWithinSelections(\n rootSelections: readonly SelectionNode[],\n offset: number,\n): PathSegment[] {\n const path: PathSegment[] = [];\n let selections = rootSelections;\n while (true) {\n const selection = selections.find(\n (s): s is FieldNode | InlineFragmentNode =>\n (s.kind === Kind.FIELD || s.kind === Kind.INLINE_FRAGMENT) &&\n s.loc != null &&\n s.loc.start <= offset &&\n s.loc.end >= offset,\n );\n if (!selection) {\n break;\n }\n if (selection.kind === Kind.FIELD) {\n path.push(fieldSegment(selection.name.value));\n } else {\n const typeName = selection.typeCondition?.name.value;\n if (!typeName) {\n break;\n }\n path.push(inlineFragmentSegment(typeName));\n }\n if (!selection.selectionSet) {\n break;\n }\n selections = selection.selectionSet.selections;\n }\n return path;\n}\n\nexport function fieldPathAtOffset(\n doc: DocumentNode,\n offset: number,\n): PathSegment[] {\n const op = doc.definitions.find(\n d =>\n d.kind === Kind.OPERATION_DEFINITION &&\n d.loc != null &&\n d.loc.start <= offset &&\n d.loc.end >= offset,\n );\n if (!op || op.kind !== Kind.OPERATION_DEFINITION) {\n return [];\n }\n return pathWithinSelections(op.selectionSet.selections, offset);\n}\n\n/**\n * Resolves the definition the cursor sits in — an operation or a named\n * fragment — together with the field path within it. Returns `undefined` when\n * the cursor is not inside any editable definition. Drives cursor-following:\n * moving the editor cursor into a fragment switches the builder to editing it.\n */\nexport function cursorContextAtOffset(\n doc: DocumentNode,\n offset: number,\n): { target: DefinitionTarget; path: PathSegment[] } | undefined {\n const def = doc.definitions.find(\n d =>\n (d.kind === Kind.OPERATION_DEFINITION ||\n d.kind === Kind.FRAGMENT_DEFINITION) &&\n d.loc != null &&\n d.loc.start <= offset &&\n d.loc.end >= offset,\n );\n if (def?.kind === Kind.OPERATION_DEFINITION) {\n return {\n target: { kind: 'operation', name: def.name?.value },\n path: pathWithinSelections(def.selectionSet.selections, offset),\n };\n }\n if (def?.kind === Kind.FRAGMENT_DEFINITION) {\n return {\n target: { kind: 'fragment', name: def.name.value },\n path: pathWithinSelections(def.selectionSet.selections, offset),\n };\n }\n return undefined;\n}\n\n/**\n * Resolves the operation to read from: the one named `operationName` when given\n * and present, otherwise the first operation definition.\n */\nfunction findOperationDefinition(doc: DocumentNode, operationName?: string) {\n const byName = operationName\n ? doc.definitions.find(\n d =>\n d.kind === Kind.OPERATION_DEFINITION &&\n d.name?.value === operationName,\n )\n : undefined;\n const op =\n byName ?? doc.definitions.find(d => d.kind === Kind.OPERATION_DEFINITION);\n return op?.kind === Kind.OPERATION_DEFINITION ? op : undefined;\n}\n\n/**\n * Matches a path segment against a selection, by schema field name or, for an\n * inline-fragment segment, by type condition. Mirrors the document-mutator path\n * model so the cursor/path helpers agree with it.\n */\nfunction selectionMatchesSegment(\n selection: SelectionNode,\n segment: PathSegment,\n): boolean {\n switch (segment.kind) {\n case 'inlineFragment':\n return (\n selection.kind === Kind.INLINE_FRAGMENT &&\n selection.typeCondition?.name.value === segment.typeName\n );\n case 'field':\n return (\n selection.kind === Kind.FIELD && selection.name.value === segment.name\n );\n }\n}\n\n/**\n * Extracts the raw, printable value string for an argument at `path` from the\n * document, e.g. `\"abc\"` for a string or `42` for an int. Returns an empty\n * string when the field, arg, or a value we can render is not found. Walks both\n * field and inline-fragment path segments.\n */\nexport function extractRawArgValue(\n doc: DocumentNode,\n path: PathSegment[],\n argName: string,\n operationName?: string,\n): string {\n const op = findOperationDefinition(doc, operationName);\n if (!op) {\n return '';\n }\n\n let selections: readonly SelectionNode[] = op.selectionSet.selections;\n for (let i = 0; i < path.length; i++) {\n const seg = path[i]!;\n const node = selections.find((s): s is FieldNode | InlineFragmentNode =>\n selectionMatchesSegment(s, seg),\n );\n if (!node) {\n return '';\n }\n if (i === path.length - 1) {\n if (node.kind !== Kind.FIELD) {\n return '';\n }\n const argNode = (node.arguments ?? []).find(\n a => a.name.value === argName,\n );\n if (!argNode) {\n return '';\n }\n const v = argNode.value;\n if (v.kind === Kind.STRING) {\n return `\"${v.value}\"`;\n }\n if (v.kind === Kind.INT || v.kind === Kind.FLOAT) {\n return v.value;\n }\n if (v.kind === Kind.BOOLEAN) {\n return String(v.value);\n }\n if (v.kind === Kind.ENUM) {\n return v.value;\n }\n return '';\n }\n if (!node.selectionSet) {\n return '';\n }\n selections = node.selectionSet.selections;\n }\n return '';\n}\n\n/** Counts the fields selected in the target operation (nested fields included). */\nexport function countSelectedFields(\n doc: DocumentNode,\n operationName?: string,\n): number {\n let count = 0;\n const op = findOperationDefinition(doc, operationName);\n if (op) {\n visit(op, {\n Field() {\n count++;\n },\n });\n }\n return count;\n}\n\n/**\n * Resolves the schema `GraphQLArgument` for the argument `argName` on the field\n * addressed by `path`, walking from the root type for `activeOpKind`. Returns\n * undefined when the field or arg can't be resolved against the schema.\n */\nexport function resolveSchemaArg(\n schema: GraphQLSchema,\n activeOpKind: OperationTypeNode | undefined,\n path: PathSegment[],\n argName: string,\n): GraphQLArgument | undefined {\n const rootType =\n schema.getRootType(activeOpKind ?? OperationTypeNode.QUERY) ??\n schema.getQueryType();\n return resolveSchemaArgFromRoot(schema, rootType ?? undefined, path, argName);\n}\n\n/**\n * Like {@link resolveSchemaArg} but walks from an explicit `rootType` rather\n * than an operation kind, so it resolves args inside a fragment (whose root is\n * its type condition) as well as inside an operation.\n */\nexport function resolveSchemaArgFromRoot(\n schema: GraphQLSchema,\n rootType: GraphQLNamedType | undefined,\n path: PathSegment[],\n argName: string,\n): GraphQLArgument | undefined {\n if (!rootType || path.length === 0) {\n return;\n }\n\n let currentType: GraphQLNamedType = rootType;\n let targetField: { args: readonly GraphQLArgument[] } | undefined;\n for (const seg of path) {\n if (seg.kind === 'inlineFragment') {\n const condition = schema.getType(seg.typeName);\n if (!condition) {\n return;\n }\n currentType = condition;\n targetField = undefined;\n continue;\n }\n if (!(isObjectType(currentType) || isInterfaceType(currentType))) {\n return;\n }\n const fields = currentType.getFields();\n const f = fields[seg.name] as\n | { type: unknown; args: readonly GraphQLArgument[] }\n | undefined;\n if (!f) {\n return;\n }\n targetField = f;\n const named = getNamedType(f.type as Parameters<typeof getNamedType>[0]);\n if (named && (isObjectType(named) || isInterfaceType(named))) {\n currentType = named;\n }\n }\n return targetField?.args.find(a => a.name === argName);\n}\n\n/**\n * Resolves the named type reached by walking `path` from the root type for\n * `activeOpKind`. Field segments descend into the field's type; `inlineFragment`\n * segments switch to that type condition. Returns undefined when a segment\n * doesn't resolve. Used to pick the type condition when extracting a field's\n * selection into a fragment.\n */\nexport function resolveFieldNamedType(\n schema: GraphQLSchema,\n activeOpKind: OperationTypeNode | undefined,\n path: PathSegment[],\n): GraphQLNamedType | undefined {\n const rootType =\n schema.getRootType(activeOpKind ?? OperationTypeNode.QUERY) ??\n schema.getQueryType();\n if (!rootType || path.length === 0) {\n return;\n }\n\n let currentType: GraphQLNamedType = rootType;\n let result: GraphQLNamedType | undefined;\n for (const seg of path) {\n if (seg.kind === 'inlineFragment') {\n const condition = schema.getType(seg.typeName);\n if (!condition) {\n return;\n }\n currentType = condition;\n result = condition;\n continue;\n }\n if (!(isObjectType(currentType) || isInterfaceType(currentType))) {\n return;\n }\n const fields = currentType.getFields();\n const f = fields[seg.name] as { type: unknown } | undefined;\n if (!f) {\n return;\n }\n const named = getNamedType(f.type as Parameters<typeof getNamedType>[0]);\n if (!named) {\n return;\n }\n result = named;\n currentType = named;\n }\n return result;\n}\n"],"mappings":";;;;;;;AA0BA,SAAgBQ,cACdC,MACyB;CACzB,IAAI,CAACA,QAAQ,CAACA,KA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AAA;GACd;EACF;EACA,IAAI,EAAE1C,aAAa0E,WAAW,KAAK3E,gBAAgB2E,WAAW,IAC5D;EAGF,MAAMO,IADSP,YAAYM,UACjBD,CAAAA,CAAO5B,IAAIvB;EAGrB,IAAI,CAACqD,GACH;EAEFN,cAAcM;EACd,MAAME,QAAQjF,aAAa+E,EAAEC,IAA0C;EACvE,IAAIC,UAAUnF,aAAamF,KAAK,KAAKpF,gBAAgBoF,KAAK,IACxDT,cAAcS;CAElB;CACA,OAAOR,aAAaC,KAAKzD,MAAKoC,MAAKA,EAAE3B,SAASoB,OAAO;AACvD"}
|
package/dist/lib/variables.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Kind, visit } from "graphql";
|
|
1
2
|
import { mapOperation, setArgInSelectionSet } from "./ast-path.js";
|
|
2
3
|
import { rawToValueNode } from "./arg-value.js";
|
|
3
|
-
import { Kind, visit } from "graphql";
|
|
4
4
|
// src/lib/variables.ts
|
|
5
5
|
/**
|
|
6
6
|
* Suggests a variable name for `argName` that does not collide with any
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variables.js","names":["Kind","visit","
|
|
1
|
+
{"version":3,"file":"variables.js","names":["Kind","visit","mapOperation","setArgInSelectionSet","rawToValueNode","suggestVarName","doc","argName","existingNames","Set","def","definitions","kind","OPERATION_DEFINITION","vd","variableDefinitions","add","variable","name","value","has","i","promoteArgToVariable","path","varName","type","defaultRaw","operationName","defaultValue","varDef","VARIABLE_DEFINITION","VARIABLE","NAME","NAMED_TYPE","directives","varValueNode","operation","newSelectionSet","selectionSet","existingVarDefs","some","replaceVariableInSelectionSet","Argument","arg","undefined","demoteVariable","inlineValue","varDefs","targetDef","find","newVarDefs","filter"],"sources":["../../src/lib/variables.ts"],"sourcesContent":["import {\n Kind,\n visit,\n type DocumentNode,\n type SelectionSetNode,\n type ValueNode,\n type VariableDefinitionNode,\n} from 'graphql';\n\nimport {\n mapOperation,\n setArgInSelectionSet,\n type PathSegment,\n} from './ast-path';\nimport { rawToValueNode } from './arg-value';\n\n/**\n * Suggests a variable name for `argName` that does not collide with any\n * existing variable definition anywhere in `doc`. The check spans every\n * operation because the variables editor is a single document-wide JSON\n * object: two operations sharing a variable name would share its value.\n * Returns `argName` when no collision exists, otherwise appends `_2`, `_3`, etc.\n */\nexport function suggestVarName(doc: DocumentNode, argName: string): string {\n const existingNames = new Set<string>();\n for (const def of doc.definitions) {\n if (def.kind === Kind.OPERATION_DEFINITION) {\n for (const vd of def.variableDefinitions ?? []) {\n existingNames.add(vd.variable.name.value);\n }\n }\n }\n\n if (!existingNames.has(argName)) {\n return argName;\n }\n let i = 2;\n while (existingNames.has(`${argName}_${i}`)) {\n i++;\n }\n return `${argName}_${i}`;\n}\n\n/**\n * Promotes a scalar argument on the field at `path` to a variable reference.\n * Adds `($varName: type = defaultRaw)` to the target operation's (by name, or\n * the first operation when unspecified) variable definitions and replaces the\n * inline argument value with `$varName`.\n *\n * When the operation is anonymous (shorthand query), it is converted to an\n * explicit `query` operation so that variable definitions can be added.\n *\n * Returns a new `DocumentNode`; does not mutate `doc`.\n */\nexport function promoteArgToVariable(\n doc: DocumentNode,\n path: PathSegment[],\n argName: string,\n varName: string,\n type: string,\n defaultRaw: string,\n operationName?: string,\n): DocumentNode {\n const defaultValue = rawToValueNode(defaultRaw);\n const varDef: VariableDefinitionNode = {\n kind: Kind.VARIABLE_DEFINITION,\n variable: {\n kind: Kind.VARIABLE,\n name: { kind: Kind.NAME, value: varName },\n },\n type: {\n kind: Kind.NAMED_TYPE,\n name: { kind: Kind.NAME, value: type },\n },\n defaultValue,\n directives: [],\n };\n\n const varValueNode: ValueNode = {\n kind: Kind.VARIABLE,\n name: { kind: Kind.NAME, value: varName },\n };\n\n return mapOperation(doc, operationName, operation => {\n const newSelectionSet = setArgInSelectionSet(\n operation.selectionSet,\n path,\n argName,\n varValueNode,\n );\n\n // The arg path didn't resolve, so nothing now references the variable; bail\n // before defining one that would dangle. (print upgrades a shorthand query\n // to `query (...) { ... }` automatically once it carries variable definitions.)\n if (newSelectionSet === operation.selectionSet) {\n return operation;\n }\n\n const existingVarDefs = operation.variableDefinitions ?? [];\n // Don't redefine a variable that already exists, e.g. promoting twice.\n const variableDefinitions = existingVarDefs.some(\n vd => vd.variable.name.value === varName,\n )\n ? existingVarDefs\n : [...existingVarDefs, varDef];\n\n return {\n ...operation,\n variableDefinitions,\n selectionSet: newSelectionSet,\n };\n });\n}\n\nexport function replaceVariableInSelectionSet(\n selectionSet: SelectionSetNode,\n varName: string,\n defaultValue: ValueNode | undefined,\n): SelectionSetNode {\n return visit(selectionSet, {\n Argument(arg) {\n if (\n arg.value.kind === Kind.VARIABLE &&\n arg.value.name.value === varName\n ) {\n return defaultValue === undefined\n ? null\n : { ...arg, value: defaultValue };\n }\n return; // leave other args untouched\n },\n });\n}\n\n/**\n * Demotes a variable back to an inline literal. Removes the variable\n * definition for `varName` from the target operation (by name, or the first\n * operation when unspecified) and replaces every `$varName` argument reference\n * with `inlineValue` when provided, otherwise the variable's default value\n * (or removes the arg entirely when there is neither).\n *\n * Returns a new `DocumentNode`; does not mutate `doc`.\n */\nexport function demoteVariable(\n doc: DocumentNode,\n varName: string,\n operationName?: string,\n inlineValue?: ValueNode,\n): DocumentNode {\n return mapOperation(doc, operationName, operation => {\n const varDefs = operation.variableDefinitions ?? [];\n const targetDef = varDefs.find(vd => vd.variable.name.value === varName);\n if (!targetDef) {\n return operation;\n }\n\n const value: ValueNode | undefined = inlineValue ?? targetDef.defaultValue;\n\n const newVarDefs = varDefs.filter(vd => vd.variable.name.value !== varName);\n const newSelectionSet = replaceVariableInSelectionSet(\n operation.selectionSet,\n varName,\n value,\n );\n\n return {\n ...operation,\n variableDefinitions: newVarDefs,\n selectionSet: newSelectionSet,\n };\n });\n}\n"],"mappings":";;;;;;;;;;;AAuBA,SAAgBK,eAAeC,KAAmBC,SAAyB;CACzE,MAAMC,gCAAgB,IAAIC,IAAY;CACtC,KAAK,MAAMC,OAAOJ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,SACAI,cACkB;CAClB,OAAO3B,MAAMqC,cAAc,EACzBI,SAASC,KAAK;EACZ,IACEA,IAAIxB,MAAMP,SAASZ,KAAK+B,YACxBY,IAAIxB,MAAMD,KAAKC,UAAUK,SAEzB,OAAOI,iBAAiBgB,KAAAA,IACpB,OACA;GAAE,GAAGD;GAAKxB,OAAOS;EAAa;CAGtC,EACF,CAAC;AACH;;;;;;;;;;AAWA,SAAgBiB,eACdvC,KACAkB,SACAG,eACAmB,aACc;CACd,OAAO5C,aAAaI,KAAKqB,gBAAeS,cAAa;EACnD,MAAMW,UAAUX,UAAUrB,uBAAuB,CAAA;EACjD,MAAMiC,YAAYD,QAAQE,MAAKnC,OAAMA,GAAGG,SAASC,KAAKC,UAAUK,OAAO;EACvE,IAAI,CAACwB,WACH,OAAOZ;EAGT,MAAMjB,QAA+B2B,eAAeE,UAAUpB;EAE9D,MAAMsB,aAAaH,QAAQI,QAAOrC,OAAMA,GAAGG,SAASC,KAAKC,UAAUK,OAAO;EAC1E,MAAMa,kBAAkBI,8BACtBL,UAAUE,cACVd,SACAL,KACF;EAEA,OAAO;GACL,GAAGiB;GACHrB,qBAAqBmC;GACrBZ,cAAcD;EAChB;CACF,CAAC;AACH"}
|
package/dist/style.css
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
.graphiql-qb-empty {
|
|
16
|
-
padding: var(--px-16);
|
|
16
|
+
padding-block: var(--px-16);
|
|
17
17
|
color: oklch(var(--fg-subtle));
|
|
18
18
|
font-size: var(--font-size-body);
|
|
19
19
|
font-family: var(--font-family);
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
align-items: center;
|
|
28
28
|
gap: var(--px-8);
|
|
29
29
|
width: 100%;
|
|
30
|
-
padding: var(--px-6)
|
|
30
|
+
padding: var(--px-6) 0;
|
|
31
31
|
border: none;
|
|
32
32
|
border-bottom: 1px solid oklch(var(--border-default));
|
|
33
33
|
background: oklch(var(--bg-elevated));
|
|
@@ -84,28 +84,10 @@
|
|
|
84
84
|
display: flex;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
.graphiql-qb-
|
|
88
|
-
box-sizing: border-box;
|
|
89
|
-
width: auto;
|
|
87
|
+
.graphiql-qb-filter-row {
|
|
90
88
|
margin: 0 var(--px-8) var(--px-6);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
border-radius: var(--radius-sm);
|
|
94
|
-
color: oklch(var(--fg-default));
|
|
95
|
-
font-family: var(--font-family);
|
|
96
|
-
font-size: var(--font-size-body);
|
|
97
|
-
border: 1px solid #0000;
|
|
98
|
-
display: block;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
.graphiql-qb-field-filter::placeholder {
|
|
102
|
-
color: oklch(var(--fg-subtle));
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
.graphiql-qb-field-filter:focus {
|
|
106
|
-
border-color: oklch(var(--accent-purple));
|
|
107
|
-
background-color: oklch(var(--bg-canvas));
|
|
108
|
-
outline: none;
|
|
89
|
+
flex-direction: column;
|
|
90
|
+
display: flex;
|
|
109
91
|
}
|
|
110
92
|
|
|
111
93
|
.graphiql-qb-show-more {
|
|
@@ -163,7 +145,7 @@
|
|
|
163
145
|
.graphiql-qb-field-header {
|
|
164
146
|
align-items: center;
|
|
165
147
|
gap: var(--px-6);
|
|
166
|
-
padding: 3px var(--px-
|
|
148
|
+
padding: 3px var(--px-8);
|
|
167
149
|
border-radius: var(--radius-sm);
|
|
168
150
|
cursor: default;
|
|
169
151
|
min-height: 26px;
|
|
@@ -358,7 +340,6 @@
|
|
|
358
340
|
gap: var(--px-4);
|
|
359
341
|
margin: var(--px-4) 0 var(--px-4) 38px;
|
|
360
342
|
padding: var(--px-6) var(--px-8);
|
|
361
|
-
background: oklch(var(--bg-subtle));
|
|
362
343
|
border-radius: var(--radius-md);
|
|
363
344
|
border: 1px solid oklch(var(--border-default));
|
|
364
345
|
flex-direction: column;
|
|
@@ -380,22 +361,11 @@
|
|
|
380
361
|
flex-shrink: 0;
|
|
381
362
|
}
|
|
382
363
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
border: 1px solid oklch(var(--border-strong));
|
|
386
|
-
border-radius: var(--radius-sm);
|
|
387
|
-
min-width: 0;
|
|
388
|
-
color: oklch(var(--fg-default));
|
|
389
|
-
font-family: var(--font-family-mono);
|
|
390
|
-
font-size: var(--font-size-eyebrow);
|
|
391
|
-
padding: 2px var(--px-6);
|
|
392
|
-
outline: none;
|
|
364
|
+
.graphiql-qb-control-wrapper {
|
|
365
|
+
flex-direction: column;
|
|
393
366
|
flex: 1;
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
input.graphiql-qb-arg-input:focus, select.graphiql-qb-arg-select:focus {
|
|
398
|
-
border-color: oklch(var(--accent-purple));
|
|
367
|
+
min-width: 0;
|
|
368
|
+
display: flex;
|
|
399
369
|
}
|
|
400
370
|
|
|
401
371
|
.graphiql-qb-arg-checkbox {
|
|
@@ -569,7 +539,7 @@ input.graphiql-qb-arg-input:focus, select.graphiql-qb-arg-select:focus {
|
|
|
569
539
|
}
|
|
570
540
|
|
|
571
541
|
.graphiql-qb-possible-types-header {
|
|
572
|
-
padding: 3px var(--px-
|
|
542
|
+
padding: 3px var(--px-8);
|
|
573
543
|
border-radius: var(--radius-sm);
|
|
574
544
|
min-height: 26px;
|
|
575
545
|
}
|
|
@@ -600,7 +570,7 @@ input.graphiql-qb-arg-input:focus, select.graphiql-qb-arg-select:focus {
|
|
|
600
570
|
.graphiql-qb-inline-fragment-header {
|
|
601
571
|
align-items: center;
|
|
602
572
|
gap: var(--px-6);
|
|
603
|
-
padding: 3px var(--px-
|
|
573
|
+
padding: 3px var(--px-8);
|
|
604
574
|
border-radius: var(--radius-sm);
|
|
605
575
|
cursor: default;
|
|
606
576
|
min-height: 26px;
|
|
@@ -640,7 +610,6 @@ input.graphiql-qb-arg-input:focus, select.graphiql-qb-arg-select:focus {
|
|
|
640
610
|
|
|
641
611
|
.graphiql-qb-fragment-section {
|
|
642
612
|
margin-top: var(--px-16);
|
|
643
|
-
padding: 0 var(--px-14);
|
|
644
613
|
border-top: 1px solid oklch(var(--border-default));
|
|
645
614
|
padding-top: var(--px-12);
|
|
646
615
|
}
|
|
@@ -675,7 +644,7 @@ input.graphiql-qb-arg-input:focus, select.graphiql-qb-arg-select:focus {
|
|
|
675
644
|
align-items: center;
|
|
676
645
|
gap: var(--px-8);
|
|
677
646
|
min-height: 30px;
|
|
678
|
-
padding: var(--px-6) var(--px-8)
|
|
647
|
+
padding: var(--px-6) var(--px-8);
|
|
679
648
|
border-radius: var(--radius-sm);
|
|
680
649
|
transition: background 80ms;
|
|
681
650
|
display: flex;
|
|
@@ -748,23 +717,6 @@ input.graphiql-qb-arg-input:focus, select.graphiql-qb-arg-select:focus {
|
|
|
748
717
|
opacity: 1;
|
|
749
718
|
}
|
|
750
719
|
|
|
751
|
-
.graphiql-qb-fragment-rename {
|
|
752
|
-
min-width: 0;
|
|
753
|
-
font-family: var(--font-family-mono);
|
|
754
|
-
font-size: var(--font-size-mono);
|
|
755
|
-
color: oklch(var(--fg-default));
|
|
756
|
-
background: oklch(var(--bg-subtle));
|
|
757
|
-
border: 1px solid oklch(var(--border-strong));
|
|
758
|
-
border-radius: var(--radius-sm);
|
|
759
|
-
padding: 1px var(--px-6);
|
|
760
|
-
flex: 1;
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
.graphiql-qb-fragment-rename:focus-visible {
|
|
764
|
-
outline: 2px solid oklch(var(--accent-purple));
|
|
765
|
-
outline-offset: 1px;
|
|
766
|
-
}
|
|
767
|
-
|
|
768
720
|
.graphiql-qb-fragment-rename-btn, .graphiql-qb-fragment-delete-btn {
|
|
769
721
|
padding: var(--px-4);
|
|
770
722
|
color: oklch(var(--fg-subtle));
|
|
@@ -876,7 +828,7 @@ input.graphiql-qb-arg-input:focus, select.graphiql-qb-arg-select:focus {
|
|
|
876
828
|
|
|
877
829
|
.graphiql-qb-fragment-editor-header {
|
|
878
830
|
gap: var(--px-12);
|
|
879
|
-
padding: var(--px-12)
|
|
831
|
+
padding-block: var(--px-12);
|
|
880
832
|
border-bottom: 1px solid oklch(var(--border-default));
|
|
881
833
|
margin-bottom: var(--px-8);
|
|
882
834
|
flex-direction: column;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphiql/plugin-query-builder",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@graphiql/react": "^1.0
|
|
36
|
+
"@graphiql/react": "^1.1.0",
|
|
37
37
|
"graphql": "^16.11.0 || ^17.0.0",
|
|
38
38
|
"react": "^18 || ^19",
|
|
39
39
|
"react-dom": "^18 || ^19"
|
|
@@ -43,27 +43,27 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@babel/core": "^7.29.6",
|
|
46
|
-
"@graphiql/react": "^1.0
|
|
47
|
-
"@storybook/addon-a11y": "^10.
|
|
48
|
-
"@storybook/addon-vitest": "^10.6.
|
|
49
|
-
"@storybook/react-vite": "^10.
|
|
46
|
+
"@graphiql/react": "^1.1.0",
|
|
47
|
+
"@storybook/addon-a11y": "^10.6.9",
|
|
48
|
+
"@storybook/addon-vitest": "^10.6.9",
|
|
49
|
+
"@storybook/react-vite": "^10.6.9",
|
|
50
50
|
"@testing-library/dom": "^10.4.0",
|
|
51
|
-
"@testing-library/jest-dom": "^
|
|
51
|
+
"@testing-library/jest-dom": "^8.0.0",
|
|
52
52
|
"@testing-library/react": "^16.3.0",
|
|
53
|
-
"@testing-library/user-event": "^14.6.
|
|
53
|
+
"@testing-library/user-event": "^14.6.13",
|
|
54
54
|
"@types/react": "^19",
|
|
55
55
|
"@types/react-dom": "^19",
|
|
56
56
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
57
|
-
"@vitejs/plugin-react": "^6.
|
|
57
|
+
"@vitejs/plugin-react": "^6.3.0",
|
|
58
58
|
"babel-plugin-react-compiler": "1.0.0",
|
|
59
|
-
"graphql": "^17.0
|
|
59
|
+
"graphql": "^17.1.0",
|
|
60
60
|
"react": "^19.1.0",
|
|
61
61
|
"react-dom": "^19.1.0",
|
|
62
|
-
"storybook": "^10.6.
|
|
63
|
-
"vite": "^8.
|
|
62
|
+
"storybook": "^10.6.9",
|
|
63
|
+
"vite": "^8.4.0",
|
|
64
64
|
"vite-plugin-dts": "^5.1.2",
|
|
65
65
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
66
|
-
"@rolldown/plugin-babel": "^0.2
|
|
66
|
+
"@rolldown/plugin-babel": "^0.3.2"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"types:check": "tsc --noEmit",
|