这是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
7 changes: 7 additions & 0 deletions console/src/components/ApiExplorer/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,12 @@ const getStateAfterClearingHistory = state => {
};
};

const getRemoteQueries = (queryUrl, cb) => {
fetch(queryUrl)
.then(resp => resp.text().then(cb))
.catch(e => console.log('Invalid query URL: ', e));
};

const apiExplorerReducer = (state = defaultState, action) => {
switch (action.type) {
case CHANGE_TAB:
Expand Down Expand Up @@ -625,4 +631,5 @@ export {
createWsClient,
focusHeaderTextbox,
unfocusTypingHeader,
getRemoteQueries,
};
2 changes: 2 additions & 0 deletions console/src/components/ApiExplorer/ApiExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ApiExplorer extends Component {
dataHeaders={this.props.dataHeaders}
numberOfTables={this.props.tables.length}
headerFocus={this.props.headerFocus}
queryParams={this.props.location.query}
/>
);

Expand All @@ -86,6 +87,7 @@ ApiExplorer.propTypes = {
route: PropTypes.object.isRequired,
tables: PropTypes.array.isRequierd,
headerFocus: PropTypes.bool.isRequired,
location: PropTypes.object.isRequired,
};

export default ApiExplorer;
2 changes: 2 additions & 0 deletions console/src/components/ApiExplorer/ApiRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ class ApiRequest extends Component {
numberOfTables={this.props.numberOfTables}
dispatch={this.props.dispatch}
headerFocus={this.props.headerFocus}
queryParams={this.props.queryParams}
/>
);
default:
Expand Down Expand Up @@ -395,6 +396,7 @@ ApiRequest.propTypes = {
route: PropTypes.object.isRequired,
numberOfTables: PropTypes.number.isRequired,
headerFocus: PropTypes.bool.isRequired,
queryParams: PropTypes.object.isRequired,
};

export default ApiRequest;
2 changes: 2 additions & 0 deletions console/src/components/ApiExplorer/ApiRequestWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ApiRequestWrapper extends Component {
dataHeaders={this.props.dataHeaders}
numberOfTables={this.props.numberOfTables}
headerFocus={this.props.headerFocus}
queryParams={this.props.queryParams}
/>
{this.props.request.bodyType !== 'graphql' ? (
<ApiResponse
Expand Down Expand Up @@ -70,6 +71,7 @@ ApiRequestWrapper.propTypes = {
dispatch: PropTypes.func,
numberOfTables: PropTypes.number,
headerFocus: PropTypes.bool.isRequired,
queryParams: PropTypes.bool.isRequired,
};

export default ApiRequestWrapper;
17 changes: 15 additions & 2 deletions console/src/components/ApiExplorer/GraphiQLWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Component } from 'react';
import GraphiQL from 'hasura-console-graphiql';
import PropTypes from 'prop-types';
import ErrorBoundary from './ErrorBoundary';
import { graphQLFetcherFinal } from './Actions';
import { graphQLFetcherFinal, getRemoteQueries } from './Actions';

import './GraphiQL.css';

Expand All @@ -14,7 +14,14 @@ class GraphiQLWrapper extends Component {
error: false,
noSchema: false,
onBoardingEnabled: false,
queries: null,
};
const queryFile = this.props.queryParams.query_file;
if (queryFile) {
getRemoteQueries(queryFile, queries =>
this.setState({ ...this.state, queries })
);
}
}

shouldComponentUpdate(nextProps) {
Expand All @@ -40,7 +47,13 @@ class GraphiQLWrapper extends Component {
);

if (!this.state.error && this.props.numberOfTables !== 0) {
content = <GraphiQL fetcher={graphQLFetcher} />;
if (this.state.queries) {
content = (
<GraphiQL fetcher={graphQLFetcher} query={this.state.queries} />
);
} else {
content = <GraphiQL fetcher={graphQLFetcher} />;
}
} else if (this.props.numberOfTables === 0) {
content = (
<GraphiQL
Expand Down