Skip to content

Commit fcc098a

Browse files
authored
Indicate when schema cannot be loaded in doc explorer. (#269)
When introspection fails to load a schema (or a schema is intentionally excluded via providing `null` as the prop), the doc explorer currently continues to show a loading indicator. This change alters that behavior to instead declare that no schema exists. This also ensures schema is set to `null` after failure to load via introspection. Fixes #212
1 parent 16d2b5e commit fcc098a

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

css/doc-explorer.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,16 @@
159159
padding: 0;
160160
width: 100%;
161161
}
162+
163+
.graphiql-container .error-container {
164+
font-weight: bold;
165+
left: 0;
166+
letter-spacing: 1px;
167+
opacity: 0.5;
168+
position: absolute;
169+
right: 0;
170+
text-align: center;
171+
text-transform: uppercase;
172+
top: 50%;
173+
transform: translate(0, -50%);
174+
}

src/components/DocExplorer.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,22 @@ export class DocExplorer extends React.Component {
6262
navItem = navStack[navStack.length - 1];
6363
}
6464

65-
let title;
65+
let title = 'Documentation Explorer';
6666
let content;
67-
if (navItem) {
67+
if (schema === undefined) {
68+
// Schema is undefined when it is being loaded via introspection.
69+
content =
70+
<div className="spinner-container">
71+
<div className="spinner" />
72+
</div>;
73+
} else if (schema === null) {
74+
// Schema is null when it explicitly does not exist, typically due to
75+
// an error during introspection.
76+
content =
77+
<div className="error-container">
78+
{'No Schema Available'}
79+
</div>;
80+
} else if (navItem) {
6881
if (navItem.name === 'Search Results') {
6982
title = navItem.name;
7083
content =
@@ -95,7 +108,6 @@ export class DocExplorer extends React.Component {
95108
}
96109
}
97110
} else if (schema) {
98-
title = 'Documentation Explorer';
99111
content =
100112
<SchemaDoc schema={schema} onClickType={this.handleClickTypeOrField} />;
101113
}
@@ -107,12 +119,6 @@ export class DocExplorer extends React.Component {
107119
prevName = navStack[navStack.length - 2].name;
108120
}
109121

110-
const spinnerDiv = (
111-
<div className="spinner-container">
112-
<div className="spinner" />
113-
</div>
114-
);
115-
116122
const shouldSearchBoxAppear = content && (
117123
content.type === SearchResults || content.type === SchemaDoc
118124
);
@@ -140,7 +146,7 @@ export class DocExplorer extends React.Component {
140146
isShown={shouldSearchBoxAppear}
141147
onSearch={this.handleSearch}
142148
/>
143-
{this.props.schema ? content : spinnerDiv}
149+
{content}
144150
</div>
145151
</div>
146152
);

src/components/GraphiQL.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,17 @@ export class GraphiQL extends React.Component {
403403
const responseString = typeof result === 'string' ?
404404
result :
405405
JSON.stringify(result, null, 2);
406-
this.setState({ response: responseString });
406+
this.setState({
407+
// Set schema to `null` to explicitly indicate that no schema exists.
408+
schema: null,
409+
response: responseString
410+
});
407411
}
408412
}).catch(error => {
409-
this.setState({ response: error && String(error.stack || error) });
413+
this.setState({
414+
schema: null,
415+
response: error && String(error.stack || error)
416+
});
410417
});
411418
}
412419

0 commit comments

Comments
 (0)