Skip to content

feat: add GraphQL SDL importer (graphqlerd.py) (#121) - #131

Merged
Agents365-ai merged 2 commits into
Agents365-ai:mainfrom
MannXo:feat/issue-121-graphql-importer
Sep 13, 2026
Merged

Agents365-ai merged 2 commits into
Agents365-ai:mainfrom
MannXo:feat/issue-121-graphql-importer

Conversation

@MannXo

@MannXo MannXo commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #121.

Adds graphqlerd.py, a GraphQL SDL importer that emits the skill's autolayout graph JSON, following the shape protoimports.py established in #128.

What it does

One node per type, interface, input, enum, union or custom scalar, each listing its fields with types and marking @deprecated. Edges for field references (labelled with the field name), implements, and union membership.

Two input modes. SDL from a .graphql / .gql file or a directory, and an introspection JSON dump.

The parser is stdlib-only, no graphql-core. It handles descriptions, comments, field arguments with defaults, list and non-null wrappers, directives and extend. Anything it does not recognise is skipped rather than guessed at, so the worst case is a missing field and never a wrong edge.

Two choices the issue left open:

  • Enums and custom scalars are dimmed, not unlinked. The issue allows either. Dimming keeps the field references visible while letting the object types carry the diagram.
  • --group buckets types by the source schema file. GraphQL has no package concept, so there was nothing native to group on. A schema split across billing.graphql and catalog.graphql is how SDL is namespaced in practice, and it invents no convention the maintainer did not ask for.

The five builtin scalars never become nodes. An introspection dump always lists them, so without that filter every introspection run gained five orphan nodes.

Registration

SKILL.md routing row and description, toolbox.md (row, entry, count 41 → 42), cookbook.md prompt, diagram-ir.md auto-detect list, mcp.md build row, CHANGELOG.md, and both READMEs (15 → 16 extractors). Wired into diagramctl.py build with .graphql / .gql auto-detection and into the MCP server's --from enum.

Directory detection is ordered after the existing language and .proto markers, matching the reasoning already in that function: a schema file is often one part of a project whose own markers describe it better.

Testing

python3 -W error::ResourceWarning -m unittest discover -s tests
Ran 216 tests ... OK (skipped=7)

188 on main, so 28 are new: tests/test_graphqlerd.py covers the parser, the graph, the introspection path and the CLI, plus one importer smoke test in tests/test_scripts.py next to the protobuf one.

Six sabotage runs, so no new test passes vacuously:

no comment/description stripping -> 2 failing
builtin scalars not excluded     -> 1 failing
no list/non-null unwrapping      -> 4 failing
edges to undefined types allowed -> 1 failing
enums styled like object types   -> 1 failing
field arguments not stripped     -> 2 failing, 1 error

Two of those started out passing under sabotage, which is how the builtin-scalar leak above was found and how the comment decoy got moved to the start of its line where the definition scan would actually reach it.

End to end, diagramctl.py build on a two-file schema directory produces a .drawio that validate.py reports with 0 errors.

Not verified

CI runs Python 3.11 and this machine only has 3.14, so the suite was not run on 3.11. The script is plain stdlib with no version-sensitive syntax, but I did not execute it there.

MannXo and others added 2 commits September 13, 2026 15:09
Parses GraphQL SDL (.graphql / .gql) or an introspection JSON dump into an
entity type diagram: one node per type, interface, input, enum, union or
custom scalar, listing each field with its type and marking @deprecated,
with edges for field references, implements and union membership.

The parser is stdlib-only. Enums and custom scalars are dimmed rather than
unlinked, and --group buckets types by the schema file they came from.

Registered in SKILL.md, toolbox.md, cookbook.md, diagram-ir.md, mcp.md, both
READMEs and the CHANGELOG, and wired into diagramctl build and the MCP server
with .graphql/.gql auto-detection.
parse_sdl emits one entry per "extend" definition, so a schema with both
"type Foo" and "extend type Foo" produced two nodes with the same id and
diagramctl build failed validation with E-DUP-ID. merge_extends now folds
same-name definitions (fields, implements, union members) into the base
entry before the graph is built, covering extends that arrive from a
different schema file too. The CLI summary line now counts merged types.

Also guards the re.match in the implements scan (Optional per the type
stubs) and adds regression tests for in-file and cross-file extends.
@Agents365-ai

Copy link
Copy Markdown
Owner

Reviewed end to end and found one real bug, now fixed in ccb3e09 (pushed to this branch):

parse_sdl emits a separate entry per extend definition, so a schema containing both type Foo { ... } and extend type Foo { ... } produced two nodes with the same id, and diagramctl.py build + validate.py failed with E-DUP-ID. merge_extends now folds same-name definitions (fields, implements, union members) into the base entry in build(), which also covers an extend arriving from a different schema file. Two regression tests added (test_extends_merge_into_a_single_node, test_extends_merge_across_schema_files), plus a guard on the re.match in the implements scan and a fix for the CLI summary line, which counted pre-merge definitions.

Everything else checked out: all registration points (SKILL.md, toolbox.md, cookbook.md, diagram-ir.md, mcp.md, both READMEs, CHANGELOG under [Unreleased], no version bump), tool count 42, extractor count 16, pi-lens-ignore on both open() calls, and the full suite passes locally (214 passed). Nice work on the parser — the skip-don't-guess stance and the blank-preserving-offset comment stripper are exactly right.

@Agents365-ai
Agents365-ai merged commit 4b111af into Agents365-ai:main Sep 13, 2026
1 check passed
timothybrush pushed a commit to timothybrush/drawio-skill that referenced this pull request Sep 14, 2026
- CHANGELOG: cut 3.4.0 (GraphQL importer Agents365-ai#131, rendered-output pitfalls Agents365-ai#132,
  365-skills distribution removed Agents365-ai#133)
- SKILL.md metadata.version 3.3.0 -> 3.4.0
- tests: align hardcoded declared version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

importer: GraphQL SDL schema -> entity type diagram (graphqlerd)

2 participants