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
|
<script lang="ts">
import type { OperationInfo } from "../graphql/operations.ts";
import type { Snippet } from "svelte";
type Props = {
disabled: boolean;
docsAvailable?: boolean;
docsOpen?: boolean;
extras?: Snippet;
historyOpen?: boolean;
onFormat?: () => void;
onRun: () => void;
onSelectOperation?: (name: string | null) => void;
onToggleDocs?: () => void;
onToggleHistory?: () => void;
operationName?: string | null;
operations?: OperationInfo[];
running: boolean;
schemaLoading: boolean;
};
let {
disabled,
docsAvailable = false,
docsOpen = false,
extras,
historyOpen = false,
onFormat,
onRun,
onSelectOperation,
onToggleDocs,
onToggleHistory,
operationName = null,
operations = [],
running,
schemaLoading
}: Props = $props();
const namedOperations = $derived(operations.filter((o) => o.name !== null));
function onPick(event: Event) {
const value = (event.currentTarget as HTMLSelectElement).value;
onSelectOperation?.(value || null);
}
</script>
<style lang="scss">
.toolbar {
align-items: center;
background: var(--graphiql-panel, #252526);
border-bottom: 1px solid var(--graphiql-border, #333);
display: flex;
gap: 0.75rem;
padding: 0.5rem 0.75rem;
}
.run {
background: var(--graphiql-accent, #0e639c);
border: none;
border-radius: 3px;
color: #fff;
cursor: pointer;
font-size: 0.875rem;
padding: 0.375rem 1rem;
&:disabled {
cursor: not-allowed;
opacity: 0.5;
}
}
.hint {
color: var(--graphiql-muted, #858585);
font-size: 0.75rem;
}
.picker {
background: var(--graphiql-bg, #1e1e1e);
border: 1px solid var(--graphiql-border, #333);
border-radius: 3px;
color: var(--graphiql-fg, #d4d4d4);
font-family: inherit;
font-size: 0.8125rem;
padding: 0.25rem 0.5rem;
}
.spacer {
flex: 1;
}
.toggle {
background: none;
border: 1px solid var(--graphiql-border, #333);
border-radius: 3px;
color: var(--graphiql-muted, #858585);
cursor: pointer;
font-family: inherit;
font-size: 0.75rem;
padding: 0.25rem 0.625rem;
&.active {
background: var(--graphiql-bg, #1e1e1e);
color: var(--graphiql-fg, #d4d4d4);
}
&:disabled {
cursor: not-allowed;
opacity: 0.4;
}
&:hover:not(:disabled) {
color: var(--graphiql-fg, #d4d4d4);
}
}
</style>
<div class="toolbar">
<button class="run" {disabled} onclick={onRun}>
{running ? "Running…" : "Run"}
</button>
{#if namedOperations.length > 1}
<select
aria-label="Operation"
class="picker"
onchange={onPick}
value={operationName ?? ""}>
<option value="">Select operation…</option>
{#each namedOperations as op}
<option value={op.name}>{op.type} {op.name}</option>
{/each}
</select>
{/if}
{#if onFormat}
<button class="toggle" {disabled} onclick={onFormat} type="button">Format</button>
{/if}
{#if extras}{@render extras()}{/if}
<span class="hint">⌘/Ctrl + Enter</span>
{#if schemaLoading}
<span class="hint">Loading schema…</span>
{/if}
<span class="spacer"></span>
{#if onToggleHistory}
<button
aria-pressed={historyOpen}
class="toggle"
class:active={historyOpen}
onclick={onToggleHistory}
type="button">History</button>
{/if}
{#if onToggleDocs}
<button
aria-pressed={docsOpen}
class="toggle"
class:active={docsOpen}
disabled={!docsAvailable}
onclick={onToggleDocs}
type="button">Docs</button>
{/if}
</div>
|