Skip to content

Commit

Permalink
Fix/graphiql endpoint (#435)
Browse files Browse the repository at this point in the history
* fix graphiql bugs

* linting
  • Loading branch information
Abby George authored Dec 7, 2018
1 parent f8aca45 commit acb90f8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
43 changes: 31 additions & 12 deletions src/GraphQLEditor/GqlEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@ import { config } from '../params';
import './GqlEditor.less';

const parameters = {};
const defaultValue = config.arrangerConfig ? 1 : 0;

class GqlEditor extends React.Component {
constructor(props) {
super(props);
this.state = {
selectedEndpointIndex: props.endpointIndex || 0,
selectedEndpointIndex: props.endpointIndex,
};
}

componentDidMount() {
if (this.props.endpointIndex && this.state.selectedEndpointIndex !== this.props.endpointIndex) {
this.selectEndpoint(this.props.endpointIndex);
}
}

getOtherIndex = index =>
+!index // will either return 0 or 1

Expand Down Expand Up @@ -54,9 +61,10 @@ class GqlEditor extends React.Component {
}

// If provided endpoint is not 0 or 1, default to 0 (graph model)
const index = this.state.selectedEndpointIndex < options.length ?
const index = this.state.selectedEndpointIndex !== null &&
this.state.selectedEndpointIndex < options.length ?
this.state.selectedEndpointIndex
: 0;
: defaultValue;

return (
<div className='gql-editor' id='graphiql'>
Expand All @@ -74,14 +82,25 @@ class GqlEditor extends React.Component {
) : null
}
</div>
<GraphiQL
fetcher={options[index].endpoint}
schema={options[index].schema}
query={parameters.query}
variables={parameters.variables}
onEditQuery={editQuery}
onEditVariables={editVariables}
/>
{
index === 0 ?
<GraphiQL
fetcher={options[index].endpoint}
query={parameters.query}
schema={options[index].schema}
variables={parameters.variables}
onEditQuery={editQuery}
onEditVariables={editVariables}
/>
:
<GraphiQL
fetcher={options[index].endpoint}
query={parameters.query}
variables={parameters.variables}
onEditQuery={editQuery}
onEditVariables={editVariables}
/>
}
</div>
);
}
Expand All @@ -94,7 +113,7 @@ GqlEditor.propTypes = {
};

GqlEditor.defaultProps = {
endpointIndex: 0,
endpointIndex: defaultValue,
};

export default GqlEditor;
2 changes: 1 addition & 1 deletion src/GraphQLEditor/GqlEditor.less
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

.gql-editor .graphiql-container {
height: calc(~"100vh - 181px - 80px");
height: calc(~"100vh - 191px - 80px");
}

.gql-editor__button {
Expand Down

0 comments on commit acb90f8

Please sign in to comment.