Skip to content

Commit 905f2e5

Browse files
Simple box model reset (#2778)
* adds box model reset for .graphiql-container children * adds new class (graphiql-sidebar-section) and associated css * updates toolbar button css * fixes broken/out-of-date test in `graphiql` * adds additional test for doc explorer fetcher-error state * disables space-comment rule for line * adds additional expectation that an error will clear UI when context provider is error-free Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com>
1 parent d04983e commit 905f2e5

8 files changed

Lines changed: 68 additions & 13 deletions

File tree

.changeset/tricky-glasses-try.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@graphiql/react": patch
3+
"graphiql": patch
4+
---
5+
6+
Adds a box-model reset for all children of the `.graphiql-container` class. This change facilitated another change to the `--sidebar-width` variable.

packages/graphiql-react/src/explorer/components/__tests__/doc-explorer.spec.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ const defaultSchemaContext: SchemaContextType = {
1313
validationErrors: [],
1414
};
1515

16+
const withErrorSchemaContext: SchemaContextType = {
17+
fetchError: 'Error fetching schema',
18+
introspect() {},
19+
isFetching: false,
20+
schema: new GraphQLSchema({ description: 'GraphQL Schema for testing' }),
21+
validationErrors: [],
22+
};
23+
1624
function DocExplorerWithContext() {
1725
return (
1826
<ExplorerContextProvider>
@@ -59,4 +67,24 @@ describe('DocExplorer', () => {
5967
container.querySelector('.graphiql-markdown-description'),
6068
).toHaveTextContent('GraphQL Schema for testing');
6169
});
70+
it('renders correctly with schema error', () => {
71+
const { rerender, container } = render(
72+
<SchemaContext.Provider value={withErrorSchemaContext}>
73+
<DocExplorerWithContext />,
74+
</SchemaContext.Provider>,
75+
);
76+
77+
const error = container.querySelector('.graphiql-doc-explorer-error');
78+
79+
expect(error).toHaveTextContent('Error fetching schema');
80+
81+
rerender(
82+
<SchemaContext.Provider value={defaultSchemaContext}>
83+
<DocExplorerWithContext />,
84+
</SchemaContext.Provider>,
85+
);
86+
87+
const errors = container.querySelectorAll('.graphiql-doc-explorer-error');
88+
expect(errors).toHaveLength(0);
89+
});
6290
});

packages/graphiql-react/src/style/root.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/* a very simple box-model reset, intentionally does not include pseudo elements */
2+
.graphiql-container * {
3+
box-sizing: border-box;
4+
}
5+
16
.graphiql-container,
27
.CodeMirror-info,
38
.CodeMirror-lint-tooltip,
@@ -57,7 +62,7 @@ reach-portal {
5762
--popover-border: none;
5863

5964
/* Layout */
60-
--sidebar-width: 44px;
65+
--sidebar-width: 60px;
6166
--toolbar-width: 40px;
6267
--session-header-height: 51px;
6368
}

packages/graphiql-react/src/toolbar/button.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
button.graphiql-toolbar-button {
2-
display: block;
2+
display: flex;
3+
align-items: center;
4+
justify-content: center;
35
height: var(--toolbar-width);
46
width: var(--toolbar-width);
57

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// eslint-disable-next-line spaced-comment
12
/// <reference types="vite/client" />

packages/graphiql/src/components/GraphiQL.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ export function GraphiQLInterface(props: GraphiQLInterfaceProps) {
323323
return (
324324
<div data-testid="graphiql-container" className="graphiql-container">
325325
<div className="graphiql-sidebar">
326-
<div>
326+
<div className="graphiql-sidebar-section">
327327
{pluginContext
328328
? pluginContext?.plugins.map(plugin => {
329329
const isVisible = plugin === pluginContext.visiblePlugin;
@@ -352,7 +352,7 @@ export function GraphiQLInterface(props: GraphiQLInterfaceProps) {
352352
})
353353
: null}
354354
</div>
355-
<div>
355+
<div className="graphiql-sidebar-section">
356356
<Tooltip label="Re-fetch GraphQL schema">
357357
<UnStyledButton
358358
type="button"

packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,23 @@ describe('GraphiQL', () => {
108108
}
109109

110110
// Use a bad fetcher for our initial render
111-
const { rerender, container } = render(<GraphiQL fetcher={firstFetcher} />);
111+
const { rerender, container, getByLabelText } = render(
112+
<GraphiQL fetcher={firstFetcher} />,
113+
);
112114
await wait();
113115

116+
fireEvent.click(getByLabelText('Show Documentation Explorer'));
117+
114118
expect(
115-
container.querySelector('.doc-explorer-contents .error-container'),
119+
container.querySelector('.graphiql-doc-explorer-error'),
116120
).toBeTruthy();
117121

118122
// Re-render with valid fetcher
119123
rerender(<GraphiQL fetcher={secondFetcher} />);
120124
await wait();
121125

122126
expect(
123-
container.querySelector('.doc-explorer-contents .error-container'),
127+
container.querySelector('.graphiql-doc-explorer-error'),
124128
).not.toBeTruthy();
125129
});
126130

packages/graphiql/src/style.css

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,31 @@
1616
padding: var(--px-8);
1717
width: var(--sidebar-width);
1818
}
19+
20+
.graphiql-container .graphiql-sidebar .graphiql-sidebar-section {
21+
display: flex;
22+
flex-direction: column;
23+
gap: var(--px-8);
24+
}
25+
1926
.graphiql-container .graphiql-sidebar button {
27+
display: flex;
28+
align-items: center;
29+
justify-content: center;
2030
color: hsla(var(--color-neutral), var(--alpha-secondary));
21-
height: var(--sidebar-width);
22-
width: var(--sidebar-width);
31+
height: calc(var(--sidebar-width) - (2 * var(--px-8)));
32+
width: calc(var(--sidebar-width) - (2 * var(--px-8)));
2333
}
34+
2435
.graphiql-container .graphiql-sidebar button.active {
2536
color: hsla(var(--color-neutral), 1);
2637
}
2738
.graphiql-container .graphiql-sidebar button:not(:first-child) {
2839
margin-top: var(--px-4);
2940
}
3041
.graphiql-container .graphiql-sidebar button > svg {
31-
height: calc(var(--sidebar-width) - (2 * var(--px-12)));
32-
padding: var(--px-12);
33-
width: calc(var(--sidebar-width) - (2 * var(--px-12)));
42+
height: var(--px-20);
43+
width: var(--px-20);
3444
}
3545

3646
/* The main content, i.e. everything except the sidebar */
@@ -144,7 +154,6 @@ button.graphiql-tab-add > svg {
144154
color: hsla(var(--color-neutral), var(--alpha-tertiary));
145155
display: block;
146156
height: calc(var(--toolbar-width) - (var(--px-8) * 2));
147-
padding: var(--px-8);
148157
width: calc(var(--toolbar-width) - (var(--px-8) * 2));
149158
}
150159

0 commit comments

Comments
 (0)