[PR #462] Load GraphQL schema from file for autocomplete #2297

Open
opened 2026-05-18 20:48:26 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mountain-loop/yaak/pull/462
Author: @VDShelk
Created: 5/15/2026
Status: 🔄 Open

Base: mainHead: feat/upload-graphql-schema


📝 Commits (2)

  • 7ecf65d Load GraphQL schema from file for autocomplete
  • 8508bb0 Extract schema file parser to lib and add tests

📊 Changes

4 files changed (+207 additions, -4 deletions)

View changed files

📝 apps/yaak-client/components/graphql/GraphQLEditor.tsx (+37 -3)
📝 apps/yaak-client/hooks/useIntrospectGraphQL.ts (+32 -1)
apps/yaak-client/lib/graphqlSchema.test.ts (+85 -0)
apps/yaak-client/lib/graphqlSchema.ts (+53 -0)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/mountain-loop/yaak/pull/462 **Author:** [@VDShelk](https://github.com/VDShelk) **Created:** 5/15/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/upload-graphql-schema` --- ### 📝 Commits (2) - [`7ecf65d`](https://github.com/mountain-loop/yaak/commit/7ecf65d73e69a67addb73d03ae8d5bb67836ae16) Load GraphQL schema from file for autocomplete - [`8508bb0`](https://github.com/mountain-loop/yaak/commit/8508bb0b82d50e5e6114a3c59b5e1688984d83bf) Extract schema file parser to lib and add tests ### 📊 Changes **4 files changed** (+207 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `apps/yaak-client/components/graphql/GraphQLEditor.tsx` (+37 -3) 📝 `apps/yaak-client/hooks/useIntrospectGraphQL.ts` (+32 -1) ➕ `apps/yaak-client/lib/graphqlSchema.test.ts` (+85 -0) ➕ `apps/yaak-client/lib/graphqlSchema.ts` (+53 -0) </details> ### 📄 Description ## 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 - [x] 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. - [x] I have read and followed [CONTRIBUTING.md](https://github.com/mountain-loop/yaak/pull/CONTRIBUTING.md). - [x] I tested this change locally. - [x] 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](https://yaak.app/feedback) 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 - [x] `tsc --noEmit` clean - [x] `vp lint` clean (no new warnings) - [x] `vp fmt --check` clean - [x] Manual: load SDL `.graphql` file → autocomplete + Documentation panel work - [x] Manual: load introspection `.json` with `{ "data": { "__schema": … } }` → same - [x] Manual: load bare `{ "__schema": … }` `.json` → same - [x] Manual: load a non-GraphQL file → red error state with useful parser message - [x] Manual: after upload, edit URL → schema is preserved (auto-introspect off) - [x] Manual: re-enable Automatic Introspection → next URL edit overwrites the upload (expected) - [x] Manual: Clear → wipes the stored schema 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-18 20:48:26 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/yaak#2297