Commit 340d33d
authored
v6: Query builder inline fragment extraction and editing (#4412)
## Summary
Reworks how the query builder handles fragments end to end.
**Extraction is now an inline row action.** Fragment extraction used to
be a single "Create fragment from selection" button pinned to the bottom
of the panel, acting on wherever the editor's text cursor happened to
sit. It now lives on the field rows: expand a composite field, tick the
children you want, and an "Extract to fragment" action appears on that
row. Triggering it lifts the selection into a named fragment and
replaces it with a spread (`user { ...UserFields }`). The generated name
(`UserFields`, de-duped when taken) stays editable in place from the
Fragments list.
**Extracted rows stay editable.** An extracted field no longer collapses
into a locked `...FragmentName` badge. It stays a normal, expandable
composite: the spread renders as a `...FragmentName` reference row among
the field's children, and ticking more fields adds them to the **base
query** alongside the spread. A field's only tie to its fragment is the
real spread in the document — it doesn't "remember" being extracted.
**Fragments are editable in place.** Because a fragment's contents are
shared across every field that spreads it, editing them needs its own
surface. The active editing target now **follows the editor cursor**:
move the cursor into a `fragment … { … }` block and the builder switches
to editing that fragment's tree, rooted at its type condition. You can
also jump in by clicking a `...FragmentName` reference row or a name in
the Fragments list; "Back to query" returns to the operation. Fragments
are flat peers — no nesting or breadcrumbs.
**The fragment reuse suggestion buttons are gone.** The short-lived "Use
...FragmentName" reuse action (and its dead helpers) is removed — it
crowded the row, and multiple matching fragments on one field overflowed
the small row.
The row actions are plain keyboard-focusable buttons. A dedicated
shortcut and keycap hint are left for the app-wide accessibility pass.
### Implementation notes
The document mutators and readers were generalized from an
operation-only `operationName` to a `DefinitionTarget` (`operation |
fragment`), so the same field tree and handlers drive operation and
fragment editing alike. Emptying a fragment is a no-op (a fragment can't
be emptied without orphaning its spreads); promote-arg-to-variable stays
operation-only.
## Test plan
- [x] Open the query builder against a schema. Expand a composite field
(e.g. `person`), tick a scalar child (e.g. `name`), and confirm an
"Extract to fragment" action appears on that row.
- [x] Trigger it. Confirm the query reads `person { ...PersonFields }`
with a `fragment PersonFields on Person { name }` block, and the
`person` row now shows a `...PersonFields` reference among its children.
- [x] With the field still expanded, tick another child (e.g. `age`).
Confirm it lands in the **base query** — `person { ...PersonFields age
}` — and the fragment is unchanged.
- [x] Click the `...PersonFields` reference row. Confirm a focused
fragment editor opens (header `PersonFields on Person`, "Back to query"
control), rooted at `Person`.
- [x] Tick a field in the fragment editor. Confirm it edits the fragment
(`fragment PersonFields on Person { name age }`) and the operation still
just spreads it.
- [x] Move the editor cursor into the `fragment PersonFields …` block.
Confirm the builder switches to editing that fragment. Move it back into
the operation; confirm it switches back.
- [x] Click a fragment's name in the Fragments list. Confirm it focuses
that fragment and is highlighted as active.
- [x] In the Fragments list, rename `PersonFields`. Confirm the
definition and every `...PersonFields` reference update together.
- [x] Keyboard-only: Tab to the extract action / reference row /
fragment name, confirm each takes focus and activates with Enter/Space.
- [x] Unit and `query-builder.cy.ts` suites pass; Storybook a11y check
clean.
Refs: #42191 parent 9341d55 commit 340d33d
38 files changed
Lines changed: 2778 additions & 527 deletions
File tree
- .changeset
- packages
- graphiql-plugin-query-builder/src
- components
- __tests__
- lib
- __tests__
- stories
- graphiql/cypress/e2e
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
133 | 135 | | |
134 | 136 | | |
135 | 137 | | |
| |||
Lines changed: 57 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
274 | 331 | | |
275 | 332 | | |
276 | 333 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| 82 | + | |
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
| |||
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| 135 | + | |
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
| |||
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
| 150 | + | |
149 | 151 | | |
150 | 152 | | |
151 | 153 | | |
| |||
163 | 165 | | |
164 | 166 | | |
165 | 167 | | |
| 168 | + | |
166 | 169 | | |
167 | 170 | | |
168 | 171 | | |
| |||
186 | 189 | | |
187 | 190 | | |
188 | 191 | | |
| 192 | + | |
189 | 193 | | |
190 | 194 | | |
191 | 195 | | |
| |||
212 | 216 | | |
213 | 217 | | |
214 | 218 | | |
| 219 | + | |
215 | 220 | | |
216 | 221 | | |
217 | 222 | | |
| |||
234 | 239 | | |
235 | 240 | | |
236 | 241 | | |
| 242 | + | |
237 | 243 | | |
238 | 244 | | |
239 | 245 | | |
| |||
257 | 263 | | |
258 | 264 | | |
259 | 265 | | |
| 266 | + | |
260 | 267 | | |
261 | 268 | | |
262 | 269 | | |
| |||
278 | 285 | | |
279 | 286 | | |
280 | 287 | | |
| 288 | + | |
281 | 289 | | |
282 | 290 | | |
283 | 291 | | |
| |||
303 | 311 | | |
304 | 312 | | |
305 | 313 | | |
| 314 | + | |
306 | 315 | | |
307 | 316 | | |
308 | 317 | | |
| |||
325 | 334 | | |
326 | 335 | | |
327 | 336 | | |
| 337 | + | |
328 | 338 | | |
329 | 339 | | |
330 | 340 | | |
| |||
348 | 358 | | |
349 | 359 | | |
350 | 360 | | |
| 361 | + | |
351 | 362 | | |
352 | 363 | | |
353 | 364 | | |
| |||
364 | 375 | | |
365 | 376 | | |
366 | 377 | | |
| 378 | + | |
367 | 379 | | |
368 | 380 | | |
369 | 381 | | |
| |||
383 | 395 | | |
384 | 396 | | |
385 | 397 | | |
| 398 | + | |
386 | 399 | | |
387 | 400 | | |
388 | 401 | | |
| |||
408 | 421 | | |
409 | 422 | | |
410 | 423 | | |
| 424 | + | |
411 | 425 | | |
412 | 426 | | |
413 | 427 | | |
| |||
434 | 448 | | |
435 | 449 | | |
436 | 450 | | |
| 451 | + | |
437 | 452 | | |
438 | 453 | | |
439 | 454 | | |
| |||
Lines changed: 79 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 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 | + | |
38 | 64 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
| 65 | + | |
43 | 66 | | |
44 | 67 | | |
45 | | - | |
| 68 | + | |
46 | 69 | | |
47 | 70 | | |
48 | 71 | | |
49 | | - | |
50 | | - | |
| 72 | + | |
| 73 | + | |
51 | 74 | | |
52 | | - | |
| 75 | + | |
53 | 76 | | |
54 | 77 | | |
55 | 78 | | |
56 | | - | |
57 | | - | |
| 79 | + | |
| 80 | + | |
58 | 81 | | |
59 | 82 | | |
60 | | - | |
61 | | - | |
| 83 | + | |
| 84 | + | |
62 | 85 | | |
63 | 86 | | |
64 | 87 | | |
65 | | - | |
| 88 | + | |
66 | 89 | | |
67 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
68 | 96 | | |
69 | 97 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 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 | + | |
75 | 134 | | |
76 | 135 | | |
0 commit comments