1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
# @eeeooolll/graphiql
A Svelte 5 GraphiQL alternative. CodeMirror 6 under the hood, runes-only state, SSR-safe, zero build config for SvelteKit consumers.
Published on npm as [`@eeeooolll/graphiql`](https://www.npmjs.com/package/@eeeooolll/graphiql).
## Install
```sh
bun add @eeeooolll/graphiql
```
Requires Svelte 5. The package ships `.svelte` sources — your SvelteKit/Vite build compiles them against your own Svelte version.
## Entry points
- `@eeeooolll/graphiql` — utilities, fetchers, stores, types (TS-only)
- `@eeeooolll/graphiql/component` — the `GraphiQL` Svelte component (default export)
- `@eeeooolll/graphiql/splitter` — the `Splitter` Svelte component (default export)
Component entry points are separate from the TS API so SvelteKit/Vite can resolve `.svelte` SFCs through their dedicated bundler hooks.
## Usage
```svelte
<script lang="ts">
import { createHttpFetcher } from "@eeeooolll/graphiql";
import GraphiQL from "@eeeooolll/graphiql/component";
const fetcher = createHttpFetcher({ url: "/graphql" });
</script>
<GraphiQL {fetcher}/>
```
Full prop list:
| Prop | Type | Default |
| ------------------ | ------------------------------- | -------------------- |
| `fetcher` | `Fetcher` (required) | — |
| `initialQuery` | `string` | `""` |
| `namespace` | `string` | `"eol-graphiql"` |
| `resultFooter` | `Snippet<[{ result: string }]>` | `undefined` |
| `storage` | `Storage` | `localStorage`-based |
| `subscriptionMode` | `"append" \| "replace"` | `"append"` |
| `tabExtras` | `Snippet<[{ tab: Tab }]>` | `undefined` |
| `theme` | `Extension` (CodeMirror) | `oneDark` |
| `toolbarExtras` | `Snippet` | `undefined` |
## Integration
The component only needs a `Fetcher` — a function that takes `{ query, variables, operationName, headers }` and returns either a `Promise<FetcherResult>` (HTTP) or an `AsyncIterable<FetcherResult>` (SSE/WS). That's the full seam. Any GraphQL server that speaks HTTP JSON works out of the box via `createHttpFetcher`.
### GraphQL Yoga
```ts
// server.ts
import { createYoga, createSchema } from "graphql-yoga";
export const yoga = createYoga({
schema: createSchema({
resolvers: { Query: { hello: () => "world" } },
typeDefs: /* GraphQL */ `type Query { hello: String }`
})
});
```
```svelte
<!-- +page.svelte -->
<script lang="ts">
import { createHttpFetcher } from "@eeeooolll/graphiql";
import GraphiQL from "@eeeooolll/graphiql/component";
const fetcher = createHttpFetcher({ url: "/graphql" });
</script>
<GraphiQL {fetcher}/>
```
Yoga's `/graphql` endpoint speaks standard JSON; no adapter needed.
### Apollo Server
```ts
// server.ts
import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
const server = new ApolloServer({ typeDefs, resolvers });
const { url } = await startStandaloneServer(server, { listen: { port: 4000 } });
```
```ts
const fetcher = createHttpFetcher({
headers: { "apollo-require-preflight": "true" },
url: "http://localhost:4000/"
});
```
The `apollo-require-preflight` header satisfies Apollo's CSRF mitigation for non-browser clients; drop it if you disable that check.
### `graphql-modules`
`graphql-modules` builds a composed schema; you still expose it over HTTP via Yoga, Apollo, or raw `graphql-http`. The GraphiQL wiring is identical — point the fetcher at whatever endpoint you mounted.
```ts
// modules/app.ts
import { createApplication, createModule, gql } from "graphql-modules";
const userModule = createModule({
id: "user",
resolvers: { Query: { me: () => ({ id: "1", name: "Ada" }) } },
typeDefs: gql`type Query { me: User } type User { id: ID! name: String! }`
});
export const app = createApplication({ modules: [userModule] });
```
```ts
// server.ts (Yoga host)
import { createYoga } from "graphql-yoga";
import { app } from "./modules/app.ts";
export const yoga = createYoga({
plugins: [app.createSubscription()],
schema: app.createSchemaForApollo()
});
```
```svelte
<script lang="ts">
import { createHttpFetcher } from "@eeeooolll/graphiql";
import GraphiQL from "@eeeooolll/graphiql/component";
const fetcher = createHttpFetcher({ url: "/graphql" });
</script>
<GraphiQL {fetcher}/>
```
### Hono / Bun / Deno
```ts
// deno
import { createHttpFetcher } from "@eeeooolll/graphiql";
const fetcher = createHttpFetcher({
fetch: globalThis.fetch,
url: "https://countries.trevorblades.com/"
});
```
The injectable `fetch` is how you plug in `undici`, a mocked fetch for tests, or a custom one that attaches auth headers.
### Custom headers (auth, tenancy)
Two places to set headers:
- **Per-request, server-wide** — pass `headers` to `createHttpFetcher`. Applied to every request.
- **Per-tab, user-editable** — use the Headers pane in the UI. Merged on top of fetcher-level headers.
```ts
const fetcher = createHttpFetcher({
headers: { authorization: `Bearer ${token}` },
url: "/graphql"
});
```
### Subscriptions
**SSE** (`graphql-sse` protocol):
```ts
import { createSseFetcher, createHttpFetcher } from "@eeeooolll/graphiql";
const http = createHttpFetcher({ url: "/graphql" });
const sse = createSseFetcher({ url: "/graphql/stream" });
// Dispatch by operation type in a wrapper:
const fetcher: Fetcher = (req) => /subscription\s/.test(req.query) ? sse(req) : http(req);
```
**WebSocket** (`graphql-ws` protocol):
```ts
import { createWsFetcher } from "@eeeooolll/graphiql";
const ws = createWsFetcher({ url: "ws://localhost:4000/graphql" });
```
Either transport returns an `AsyncIterable<FetcherResult>`; the component handles streaming into the result pane per the `subscriptionMode` prop.
### Custom fetcher
Anything that matches the `Fetcher` signature works. Useful for request batching or injecting trace headers:
```ts
import type { Fetcher } from "@eeeooolll/graphiql";
const traced: Fetcher = async (req) => {
const traceId = crypto.randomUUID();
const response = await fetch("/graphql", {
body: JSON.stringify(req),
headers: { "content-type": "application/json", "x-trace-id": traceId },
method: "POST"
});
return response.json();
};
```
### Persisted queries (APQ)
`createApqFetcher` implements the Apollo Automatic Persisted Queries protocol — first request sends only the SHA-256 hash; on `PersistedQueryNotFound` the fetcher retries with the full query and the server caches the mapping. HTTP-only.
```ts
import { createApqFetcher } from "@eeeooolll/graphiql";
const fetcher = createApqFetcher({
url: "/graphql"
});
```
Pass `disable: true` to bypass the two-step dance (full query on every request) for debugging. Hashes are cached per-fetcher in memory; no disk persistence.
## Keyboard shortcuts
| Shortcut | Action |
| ----------------------------- | --------------- |
| `Cmd/Ctrl + Enter` | Run query |
| `Cmd/Ctrl + Shift + Enter` | New tab |
| `Cmd/Ctrl + Shift + W` | Close tab |
| `Cmd/Ctrl + Shift + F` | Format query |
| `Cmd/Ctrl + Alt + Right/Left` | Next / prev tab |
`Cmd+T` and `Cmd+W` aren't used because browsers reserve them; embedders running in Tauri/Electron can remap via `matchShortcut` (exported from the package).
## Session export/import
```ts
import { validateSessionExport } from "@eeeooolll/graphiql";
const json = JSON.parse(rawText);
const result = validateSessionExport(json);
if ("error" in result)
console.error(result.error);
else
console.log(`${result.tabs.length} tabs ready to import`);
```
The History panel ships Export/Import buttons that round-trip through this validator. Import accepts version-1 exports, caps at 50 tabs, and rejects strings over 1 MB.
## Theming
CSS custom properties drive the chrome:
- `--graphiql-accent`
- `--graphiql-bg`
- `--graphiql-border`
- `--graphiql-fg`
- `--graphiql-font`
- `--graphiql-muted`
- `--graphiql-panel`
The editor theme is a separate CodeMirror `Extension` passed via the `theme` prop. Ships with `oneDark` (default) and `lightTheme`:
```svelte
<script lang="ts">
import { lightTheme } from "@eeeooolll/graphiql";
import GraphiQL from "@eeeooolll/graphiql/component";
</script>
<GraphiQL {fetcher} theme={lightTheme}/>
```
## License
MIT
|