Skip to content

Commit f480fd2

Browse files
authored
Merge pull request #3031 from linucks/graphiql-broken-schema
fix(graphiql): Allow GraphiQL to run even if a valid schema cannot be returned.
2 parents 6698982 + 6245643 commit f480fd2

File tree

11 files changed

+37
-28
lines changed

11 files changed

+37
-28
lines changed

build/app.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react', 'react-dom', 'wp-element', 'wp-hooks'), 'version' => 'b46a34de121156c88432');
1+
<?php return array('dependencies' => array('react', 'react-dom', 'wp-element', 'wp-hooks'), 'version' => 'e4db36ac3a701438f12c');

build/app.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react', 'react-dom', 'wp-element'), 'version' => 'afcdd7bc76e2b7fe5cd5');
1+
<?php return array('dependencies' => array('react', 'react-dom', 'wp-element'), 'version' => '8737563331968d8f0aa0');

build/graphiqlQueryComposer.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/index.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('wp-element', 'wp-hooks'), 'version' => '16cb921597c1ed7eed91');
1+
<?php return array('dependencies' => array('wp-element', 'wp-hooks'), 'version' => '4e3fb6c1c0df33a85f55');

build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/graphiql-query-composer/components/Explorer.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@ const { useState, useEffect } = wp.element;
1717
const Wrapper = ({ schema, children }) => {
1818
if (!schema) {
1919
return (
20-
<div
21-
style={{
22-
fontFamily: "sans-serif",
23-
textAlign: `center`,
24-
}}
25-
className="error-container"
26-
>
27-
<Spin />
20+
// Wrap in graphiql-container div so error message matches that in the Documentation Explorer
21+
<div className="graphiql-container">
22+
<div className="error-container">
23+
No Schema Available
24+
</div>
2825
</div>
2926
);
3027
}

packages/wpgraphiql/components/Router/Router.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ const Router = (props) => {
137137
screen: StringParam,
138138
});
139139

140-
const { endpoint, schema, setSchema } = useAppContext();
140+
const { endpoint, schema, setSchema, setSchemaLoading } = useAppContext();
141141

142142
const { screen } = queryParams;
143143

@@ -150,18 +150,27 @@ const Router = (props) => {
150150

151151
const remoteQuery = getIntrospectionQuery();
152152

153+
const querySucccess = (res) => {
154+
const clientSchema = res?.data ? buildClientSchema(res.data) : null;
155+
if (clientSchema !== schema) {
156+
setSchema(clientSchema);
157+
}
158+
setSchemaLoading(false);
159+
}
160+
161+
const queryFailure = (res) => {
162+
console.error(`Failure running getIntrospectionQuery: ${JSON.stringify(res, null, 2)}`);
163+
setSchemaLoading(false);
164+
}
165+
166+
setSchemaLoading(true);
153167
client(endpoint)
154168
.query({
155169
query: gql`
156170
${remoteQuery}
157171
`,
158172
})
159-
.then((res) => {
160-
const clientSchema = res?.data ? buildClientSchema(res.data) : null;
161-
if (clientSchema !== schema) {
162-
setSchema(clientSchema);
163-
}
164-
});
173+
.then(querySucccess, queryFailure);
165174
}, [endpoint]);
166175

167176
const getActiveScreenName = () => {

packages/wpgraphiql/context/AppContext.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const AppContextProvider = ({
3939
queryParams,
4040
}) => {
4141
const [schema, setSchema] = useState(null);
42+
const [schemaLoading, setSchemaLoading] = useState(true);
4243
const [nonce, setNonce] = useState(getNonce());
4344
const [endpoint, setEndpoint] = useState(getEndpoint());
4445
const [_queryParams, _setQueryParams] = useState(queryParams);
@@ -55,6 +56,8 @@ export const AppContextProvider = ({
5556
setNonce,
5657
schema,
5758
setSchema,
59+
schemaLoading,
60+
setSchemaLoading,
5861
queryParams: _queryParams,
5962
setQueryParams: updateQueryParams,
6063
};

0 commit comments

Comments
 (0)