Skip to content
Open
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
28 changes: 26 additions & 2 deletions src/Explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
isScalarType,
isUnionType,
isWrappingType,
buildClientSchema,
getIntrospectionQuery,
parse,
print,
} from 'graphql';
Expand Down Expand Up @@ -68,6 +70,7 @@ type Props = {
query: string,
width?: number,
title?: string,
fetcher?: any => Promise<{data: any}>,
schema?: ?GraphQLSchema,
onEdit: string => void,
getDefaultFieldNames?: ?(type: GraphQLObjectType) => Array<string>,
Expand Down Expand Up @@ -1428,26 +1431,47 @@ class RootView extends React.PureComponent<RootViewProps, {}> {
}
}

class Explorer extends React.PureComponent<Props, State> {
class Explorer extends React.PureComponent<Props, {schema: ?GraphQLSchema}> {
static defaultProps = {
getDefaultFieldNames: defaultGetDefaultFieldNames,
getDefaultScalarArgValue: defaultGetDefaultScalarArgValue,
};

state = {schema: this.props.schema};

_ref: ?any;
_resetScroll = () => {
const container = this._ref;
if (container) {
container.scrollLeft = 0;
}
};
_fetchSchema = () => {
const {fetcher} = this.props;

if (fetcher) {
fetcher({
query: getIntrospectionQuery()
}).then(result => {
if (this.state.schema !== undefined) {
return;
}

this.setState({ schema: buildClientSchema(result.data) });
});
}
}
componentDidMount() {
if (this.state.schema === undefined) {
this._fetchSchema();
}
this._resetScroll();
}
_onEdit = (query: string): void => this.props.onEdit(query);

render() {
const {schema, query, makeDefaultArg} = this.props;
const {query, makeDefaultArg} = this.props;
const {schema} = this.state;

if (!schema) {
return (
Expand Down