这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions console/src/components/ApiExplorer/GraphiQLWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class GraphiQLWrapper extends Component {
renderGraphiql={renderGraphiql}
endpoint={graphqlNetworkData.url}
headers={graphqlNetworkData.headers}
headerFocus={headerFocus}
query={queryString}
/>
</div>
Expand Down
39 changes: 38 additions & 1 deletion console/src/components/ApiExplorer/OneGraphExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,39 @@ class OneGraphExplorer extends React.Component {
schema: null,
query: this.props.query,
isResizing: false,
headers: []
};

componentDidMount() {
this.introspect();
}

componentDidUpdate() {
if (this.shouldIntrospect(this.props.headers, this.state.headers)) {
this.introspect()
}
}

shouldIntrospect(newHeadersArray, oldHeadersArray) {
if (this.props.headerFocus) {
return false;
}
const oldHeaders = getHeadersAsJSON(oldHeadersArray);
const headers = getHeadersAsJSON(newHeadersArray);
if (Object.keys(oldHeaders).length !== Object.keys(headers).length) {
return true;
}
for (var i = Object.keys(headers).length - 1; i >= 0; i--) {
const key = Object.keys(headers)[i];
const value = headers[key];
if (oldHeaders[key] !== value) {
return true;
}
}
return false;
}

introspect() {
const { endpoint, headers } = this.props;
fetch(endpoint, {
method: 'POST',
Expand All @@ -34,8 +64,15 @@ class OneGraphExplorer extends React.Component {
.then(result => {
this.setState({
schema: buildClientSchema(result.data),
headers: JSON.parse(JSON.stringify(headers))
});
});
})
.catch(error => {
this.setState({
schema: null,
headers: JSON.parse(JSON.stringify(headers))
});
})
}

onExplorerResize = e => {
Expand Down
2 changes: 1 addition & 1 deletion console/src/components/ApiExplorer/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const getHeadersAsJSON = headers => {
const getHeadersAsJSON = (headers = []) => {
const headerJSON = {};
const nonEmptyHeaders = headers.filter(header => {
return header.key && header.isActive;
Expand Down