Skip to content

Load GraphQL schema from file for autocomplete#462

Open
VDShelk wants to merge 2 commits into
mountain-loop:mainfrom
VDShelk:feat/upload-graphql-schema
Open

Load GraphQL schema from file for autocomplete#462
VDShelk wants to merge 2 commits into
mountain-loop:mainfrom
VDShelk:feat/upload-graphql-schema

Conversation

@VDShelk
Copy link
Copy Markdown

@VDShelk VDShelk commented May 15, 2026

Summary

Adds a "Load Schema from File…" item to the existing GraphQL schema dropdown that lets users populate the editor's autocomplete schema from a local file instead of (or in addition to) running an introspection request against a server.

Useful when:

  • Working against a private/staging API where introspection is disabled or unreachable
  • Working offline against a locally-generated SDL or saved introspection result
  • Iterating on a schema before the server is even up

Submission

  • This PR is a bug fix or small-scope improvement.
  • If this PR is not a bug fix or small-scope improvement, I linked an approved feedback item below.
  • I have read and followed CONTRIBUTING.md.
  • I tested this change locally.
  • I added or updated tests when reasonable.

Scope (re. CONTRIBUTING.md)

I believe this fits the "small-scope improvement directly tied to existing behavior" bucket — happy to file an approved feedback item instead if you'd prefer:

  • No new tauri commands, no new database tables, no new model types.
  • Reuses the existing graphql_introspection table and models_upsert_graphql_introspection command.
  • Reuses the existing dropdown, the existing buildClientSchema parser, the existing error UI, and the existing autoIntrospectDisabled localStorage toggle.
  • Frontend-only: 2 files, ~125 net insertions.

What it accepts

The file picker accepts .graphql / .graphqls / .gql / .json. The parser normalizes three shapes into the single { data: <introspection> } JSON that the hook already persists:

  1. Introspection result with data wrapper — what getIntrospectionQuery() returns from a server: { "data": { "__schema": ... } }. Stored verbatim.
  2. Introspection result without wrapper{ "__schema": ... }. Wrapped before storage.
  3. SDL — fed through buildSchema()introspectionFromSchema() from graphql-js (already a direct dep), then wrapped before storage.

If parsing fails, the existing "Introspection Failed" error UI is reused.

Auto-disable behavior

After a successful file load, Automatic Introspection is toggled off for that specific request. Without this, the next URL/method edit re-fires the introspection effect and clobbers the schema the user just loaded from disk. The user can re-enable from the same dropdown — the existing per-request toggle is unchanged.

This is the only opinionated UX choice in the PR; happy to revert if you'd rather not touch the toggle and let the user manage it manually.

Test plan

  • tsc --noEmit clean
  • vp lint clean (no new warnings)
  • vp fmt --check clean
  • Manual: load SDL .graphql file → autocomplete + Documentation panel work
  • Manual: load introspection .json with { "data": { "__schema": … } } → same
  • Manual: load bare { "__schema": … } .json → same
  • Manual: load a non-GraphQL file → red error state with useful parser message
  • Manual: after upload, edit URL → schema is preserved (auto-introspect off)
  • Manual: re-enable Automatic Introspection → next URL edit overwrites the upload (expected)
  • Manual: Clear → wipes the stored schema

🤖 Generated with Claude Code

VDShelk and others added 2 commits May 15, 2026 09:33
Adds a "Load Schema from File…" item to the GraphQL schema dropdown
that lets users pick a `.graphql`/`.graphqls`/`.gql` SDL file or a
`.json` introspection result (with or without the `{ "data": ... }`
wrapper) to populate the editor's autocomplete schema without hitting
a server.

Loading a schema from disk also auto-disables Automatic Introspection
for that request so subsequent URL/method edits don't overwrite the
uploaded schema. The toggle remains available in the same dropdown.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Move tryBuildIntrospectionFromFile out of useIntrospectGraphQL into
apps/yaak-client/lib/graphqlSchema.ts as a pure function, and add unit
tests covering the three input shapes (introspection JSON with and
without { data } wrapper, SDL) plus the error paths.

Matches the existing repo pattern of testing pure-function helpers in
lib/ (see lib/model_util.ts <-> lib/model_util.test.ts). The hook now
only imports the helper.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant