Load GraphQL schema from file for autocomplete#462
Open
VDShelk wants to merge 2 commits into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Submission
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:
graphql_introspectiontable andmodels_upsert_graphql_introspectioncommand.buildClientSchemaparser, the existing error UI, and the existingautoIntrospectDisabledlocalStorage toggle.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:datawrapper — whatgetIntrospectionQuery()returns from a server:{ "data": { "__schema": ... } }. Stored verbatim.{ "__schema": ... }. Wrapped before storage.buildSchema()→introspectionFromSchema()fromgraphql-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 --noEmitcleanvp lintclean (no new warnings)vp fmt --checkclean.graphqlfile → autocomplete + Documentation panel work.jsonwith{ "data": { "__schema": … } }→ same{ "__schema": … }.json→ same🤖 Generated with Claude Code