diff --git a/src/components/GraphiQL.js b/src/components/GraphiQL.js
index ddb3caa6898..1d1560cfb98 100644
--- a/src/components/GraphiQL.js
+++ b/src/components/GraphiQL.js
@@ -132,7 +132,7 @@ export class GraphiQL extends React.Component {
// Determine the initial query to display.
const query =
props.query !== undefined ? props.query :
- this._storageGet('query') !== undefined ? this._storageGet('query') :
+ this._storageGet('query') !== null ? this._storageGet('query') :
props.defaultQuery !== undefined ? props.defaultQuery :
defaultQuery;
diff --git a/src/components/__tests__/GraphiQL-test.js b/src/components/__tests__/GraphiQL-test.js
index 4a40697a919..06e69e7c2bb 100644
--- a/src/components/__tests__/GraphiQL-test.js
+++ b/src/components/__tests__/GraphiQL-test.js
@@ -13,6 +13,24 @@ import { renderIntoDocument } from 'react-addons-test-utils';
import { GraphiQL } from '../GraphiQL';
+const mockStorage = (function () {
+ let store = {};
+ return {
+ getItem(key) {
+ return store.hasOwnProperty(key) ? store[key] : null;
+ },
+ setItem(key, value) {
+ store[key] = value.toString();
+ },
+ clear() {
+ store = {};
+ }
+ };
+}());
+
+Object.defineProperty(window, 'localStorage', {
+ value: mockStorage,
+});
describe('GraphiQL', () => {
const noOpFetcher = () => {};
@@ -36,4 +54,20 @@ describe('GraphiQL', () => {
)).to.not.throw();
});
+
+ it('defaults to the built-in default query', () => {
+ const graphiQL = renderIntoDocument();
+ expect(graphiQL.state.query).to.include('# Welcome to GraphiQL');
+ });
+
+ it('accepts a custom default query', () => {
+ const graphiQL = renderIntoDocument(
+
+ );
+
+ expect(graphiQL.state.query).to.equal('GraphQL Party!!');
+ });
});