@arcblock/graphql-playground 2.1.58 → 2.1.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/GraphqlPlayground.stories.js +60 -0
- package/lib/demo/basic.js +32 -0
- package/lib/demo/kitchen-sink.js +33 -0
- package/lib/demo/with-code-exporter.js +32 -0
- package/lib/demo/with-history.js +31 -0
- package/lib/demo/with-query-composer.js +30 -0
- package/lib/index.js +4 -61
- package/package.json +4 -4
- package/src/GraphqlPlayground.stories.js +16 -0
- package/src/demo/basic.js +26 -0
- package/src/demo/kitchen-sink.js +26 -0
- package/src/demo/with-code-exporter.js +25 -0
- package/src/demo/with-history.js +25 -0
- package/src/demo/with-query-composer.js +24 -0
- package/src/index.js +1 -62
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Basic", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _basic.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "KitchenSink", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _kitchenSink.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "WithCodeExporter", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _withCodeExporter.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "WithHistory", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _withHistory.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "WithQueryComposer", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _withQueryComposer.default;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
exports.default = void 0;
|
|
37
|
+
|
|
38
|
+
var _basic = _interopRequireDefault(require("./demo/basic"));
|
|
39
|
+
|
|
40
|
+
var _withHistory = _interopRequireDefault(require("./demo/with-history"));
|
|
41
|
+
|
|
42
|
+
var _withQueryComposer = _interopRequireDefault(require("./demo/with-query-composer"));
|
|
43
|
+
|
|
44
|
+
var _withCodeExporter = _interopRequireDefault(require("./demo/with-code-exporter"));
|
|
45
|
+
|
|
46
|
+
var _kitchenSink = _interopRequireDefault(require("./demo/kitchen-sink"));
|
|
47
|
+
|
|
48
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
49
|
+
|
|
50
|
+
var _default = {
|
|
51
|
+
title: 'UX/GraphQLPlayground',
|
|
52
|
+
parameters: {
|
|
53
|
+
docs: {
|
|
54
|
+
description: {
|
|
55
|
+
component: 'A GraphQL Playground component built on top of `graphql/graphiql`'
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.default = _default;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = Basic;
|
|
7
|
+
|
|
8
|
+
var _ = _interopRequireDefault(require(".."));
|
|
9
|
+
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
const betaQuery = "{\n getChainInfo {\n code\n info {\n network\n moniker\n }\n }\n}";
|
|
15
|
+
|
|
16
|
+
function Basic() {
|
|
17
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
18
|
+
style: {
|
|
19
|
+
minWidth: '1280px',
|
|
20
|
+
height: '40vh',
|
|
21
|
+
border: '1px solid #EEE'
|
|
22
|
+
},
|
|
23
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
|
|
24
|
+
defaultQuery: betaQuery,
|
|
25
|
+
endpoint: "https://beta.abtnetwork.io/api/",
|
|
26
|
+
title: "Beta Chain",
|
|
27
|
+
enableQueryComposer: false,
|
|
28
|
+
enableCodeExporter: false,
|
|
29
|
+
enableHistory: false
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = KitchenSink;
|
|
7
|
+
|
|
8
|
+
var _ = _interopRequireDefault(require(".."));
|
|
9
|
+
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
const betaQuery = "{\n getChainInfo {\n code\n info {\n network\n moniker\n }\n }\n}";
|
|
15
|
+
|
|
16
|
+
function KitchenSink() {
|
|
17
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
18
|
+
style: {
|
|
19
|
+
minWidth: '1280px',
|
|
20
|
+
height: '40vh',
|
|
21
|
+
border: '1px solid #EEE',
|
|
22
|
+
marginTop: '16px'
|
|
23
|
+
},
|
|
24
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
|
|
25
|
+
defaultQuery: betaQuery,
|
|
26
|
+
endpoint: "https://beta.abtnetwork.io/api/",
|
|
27
|
+
title: "Beta Chain",
|
|
28
|
+
enableHistory: true,
|
|
29
|
+
enableQueryComposer: true,
|
|
30
|
+
enableCodeExporter: true
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = WithCodeExporter;
|
|
7
|
+
|
|
8
|
+
var _ = _interopRequireDefault(require(".."));
|
|
9
|
+
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
const betaQuery = "{\n getChainInfo {\n code\n info {\n network\n moniker\n }\n }\n}";
|
|
15
|
+
|
|
16
|
+
function WithCodeExporter() {
|
|
17
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
18
|
+
style: {
|
|
19
|
+
minWidth: '1280px',
|
|
20
|
+
height: '40vh',
|
|
21
|
+
border: '1px solid #EEE',
|
|
22
|
+
marginTop: '16px'
|
|
23
|
+
},
|
|
24
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
|
|
25
|
+
defaultQuery: betaQuery,
|
|
26
|
+
endpoint: "https://beta.abtnetwork.io/api/",
|
|
27
|
+
title: "Beta Chain",
|
|
28
|
+
enableQueryComposer: false,
|
|
29
|
+
enableCodeExporter: true
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = WithHistory;
|
|
7
|
+
|
|
8
|
+
var _ = _interopRequireDefault(require(".."));
|
|
9
|
+
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
const betaQuery = "{\n getChainInfo {\n code\n info {\n network\n moniker\n }\n }\n}";
|
|
15
|
+
|
|
16
|
+
function WithHistory() {
|
|
17
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
18
|
+
style: {
|
|
19
|
+
width: '1280px',
|
|
20
|
+
height: '40vh',
|
|
21
|
+
border: '1px solid #EEE'
|
|
22
|
+
},
|
|
23
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
|
|
24
|
+
defaultQuery: betaQuery,
|
|
25
|
+
endpoint: "https://beta.abtnetwork.io/api/",
|
|
26
|
+
title: "Beta Chain",
|
|
27
|
+
enableQueryComposer: false,
|
|
28
|
+
enableHistory: true
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = WithQueryComposer;
|
|
7
|
+
|
|
8
|
+
var _ = _interopRequireDefault(require(".."));
|
|
9
|
+
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
const betaQuery = "{\n getChainInfo {\n code\n info {\n network\n moniker\n }\n }\n}";
|
|
15
|
+
|
|
16
|
+
function WithQueryComposer() {
|
|
17
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
18
|
+
style: {
|
|
19
|
+
minWidth: '1280px',
|
|
20
|
+
height: '40vh',
|
|
21
|
+
border: '1px solid #EEE'
|
|
22
|
+
},
|
|
23
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
|
|
24
|
+
defaultQuery: betaQuery,
|
|
25
|
+
endpoint: "https://beta.abtnetwork.io/api/",
|
|
26
|
+
title: "Beta Chain",
|
|
27
|
+
enableQueryComposer: true
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -45,16 +45,16 @@ const _excluded = ["endpoint", "title", "enableCodeExporter", "enableQueryCompos
|
|
|
45
45
|
|
|
46
46
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
47
47
|
|
|
48
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
49
|
-
|
|
50
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
51
|
-
|
|
52
48
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
53
49
|
|
|
54
50
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
55
51
|
|
|
56
52
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
57
53
|
|
|
54
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
55
|
+
|
|
56
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
57
|
+
|
|
58
58
|
function HistoryToggleButton() {
|
|
59
59
|
const {
|
|
60
60
|
toggle
|
|
@@ -109,59 +109,6 @@ function GraphQLPlayground(props) {
|
|
|
109
109
|
|
|
110
110
|
}, []);
|
|
111
111
|
|
|
112
|
-
const onInspect = (cm, mousePos) => {
|
|
113
|
-
const parsedQuery = (0, _graphql.parse)(query || '');
|
|
114
|
-
|
|
115
|
-
if (!parsedQuery) {
|
|
116
|
-
// eslint-disable-next-line quotes
|
|
117
|
-
console.error("Couldn't parse query document");
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const token = cm.getTokenAt(mousePos);
|
|
122
|
-
const start = {
|
|
123
|
-
line: mousePos.line,
|
|
124
|
-
ch: token.start
|
|
125
|
-
};
|
|
126
|
-
const end = {
|
|
127
|
-
line: mousePos.line,
|
|
128
|
-
ch: token.end
|
|
129
|
-
};
|
|
130
|
-
const relevantMousePos = {
|
|
131
|
-
start: cm.indexFromPos(start),
|
|
132
|
-
end: cm.indexFromPos(end)
|
|
133
|
-
};
|
|
134
|
-
const position = relevantMousePos;
|
|
135
|
-
const def = parsedQuery.definitions.find(definition => {
|
|
136
|
-
if (!definition.loc) {
|
|
137
|
-
// eslint-disable-next-line no-console
|
|
138
|
-
console.log('Missing location information for definition');
|
|
139
|
-
return false;
|
|
140
|
-
} // eslint-disable-next-line no-shadow
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const {
|
|
144
|
-
start,
|
|
145
|
-
end
|
|
146
|
-
} = definition.loc;
|
|
147
|
-
return start <= position.start && end >= position.end;
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
if (!def) {
|
|
151
|
-
console.error('Unable to find definition corresponding to mouse position');
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const operationKind = def.kind === 'OperationDefinition' ? def.operation : def.kind === 'FragmentDefinition' ? 'fragment' : 'unknown';
|
|
156
|
-
const operationName = def.kind === 'OperationDefinition' && !!def.name ? def.name.value : def.kind === 'FragmentDefinition' && !!def.name ? def.name.value : 'unknown';
|
|
157
|
-
const selector = ".graphiql-explorer-root #".concat(operationKind, "-").concat(operationName);
|
|
158
|
-
const element = document.querySelector(selector);
|
|
159
|
-
|
|
160
|
-
if (element) {
|
|
161
|
-
element.scrollIntoView();
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
|
|
165
112
|
const onEditQuery = newQuery => {
|
|
166
113
|
if (newQuery !== query && newProps.persistentQuery) {
|
|
167
114
|
persistQuery(newQuery);
|
|
@@ -230,10 +177,6 @@ function GraphQLPlayground(props) {
|
|
|
230
177
|
return;
|
|
231
178
|
}
|
|
232
179
|
|
|
233
|
-
const editor = graphiql.current.getQueryEditor();
|
|
234
|
-
editor.setOption('extraKeys', _objectSpread(_objectSpread({}, editor.options.extraKeys || {}), {}, {
|
|
235
|
-
'Shift-Alt-LeftClick': onInspect
|
|
236
|
-
}));
|
|
237
180
|
setSchema((0, _graphql.buildClientSchema)(result.data));
|
|
238
181
|
}); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
239
182
|
}, [graphiql.current]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/graphql-playground",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.61",
|
|
4
4
|
"description": "A React Component to interact with GraphQL APIs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"url": "git+https://github.com/ArcBlock/ux.git"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
|
-
"lint": "eslint src
|
|
23
|
+
"lint": "eslint src tests",
|
|
24
24
|
"build": "babel src --out-dir lib --copy-files",
|
|
25
25
|
"watch": "babel src --out-dir lib -w --copy-files",
|
|
26
26
|
"precommit": "CI=1 yarn test",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"url": "https://github.com/ArcBlock/ux/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@arcblock/ux": "^2.1.
|
|
36
|
+
"@arcblock/ux": "^2.1.61",
|
|
37
37
|
"axios": "^0.21.2",
|
|
38
38
|
"core-js": "^3.6.4",
|
|
39
39
|
"graphiql": "^1.9.11",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
60
60
|
"jest": "^24.1.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "4859674457581033b59d02723c976fffd3a9c3b3"
|
|
63
63
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { default as Basic } from './demo/basic';
|
|
2
|
+
export { default as WithHistory } from './demo/with-history';
|
|
3
|
+
export { default as WithQueryComposer } from './demo/with-query-composer';
|
|
4
|
+
export { default as WithCodeExporter } from './demo/with-code-exporter';
|
|
5
|
+
export { default as KitchenSink } from './demo/kitchen-sink';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'UX/GraphQLPlayground',
|
|
9
|
+
parameters: {
|
|
10
|
+
docs: {
|
|
11
|
+
description: {
|
|
12
|
+
component: 'A GraphQL Playground component built on top of `graphql/graphiql`',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import GraphQLPlayground from '..';
|
|
2
|
+
|
|
3
|
+
const betaQuery = `{
|
|
4
|
+
getChainInfo {
|
|
5
|
+
code
|
|
6
|
+
info {
|
|
7
|
+
network
|
|
8
|
+
moniker
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}`;
|
|
12
|
+
|
|
13
|
+
export default function Basic() {
|
|
14
|
+
return (
|
|
15
|
+
<div style={{ minWidth: '1280px', height: '40vh', border: '1px solid #EEE' }}>
|
|
16
|
+
<GraphQLPlayground
|
|
17
|
+
defaultQuery={betaQuery}
|
|
18
|
+
endpoint="https://beta.abtnetwork.io/api/"
|
|
19
|
+
title="Beta Chain"
|
|
20
|
+
enableQueryComposer={false}
|
|
21
|
+
enableCodeExporter={false}
|
|
22
|
+
enableHistory={false}
|
|
23
|
+
/>
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import GraphQLPlayground from '..';
|
|
2
|
+
|
|
3
|
+
const betaQuery = `{
|
|
4
|
+
getChainInfo {
|
|
5
|
+
code
|
|
6
|
+
info {
|
|
7
|
+
network
|
|
8
|
+
moniker
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}`;
|
|
12
|
+
|
|
13
|
+
export default function KitchenSink() {
|
|
14
|
+
return (
|
|
15
|
+
<div style={{ minWidth: '1280px', height: '40vh', border: '1px solid #EEE', marginTop: '16px' }}>
|
|
16
|
+
<GraphQLPlayground
|
|
17
|
+
defaultQuery={betaQuery}
|
|
18
|
+
endpoint="https://beta.abtnetwork.io/api/"
|
|
19
|
+
title="Beta Chain"
|
|
20
|
+
enableHistory
|
|
21
|
+
enableQueryComposer
|
|
22
|
+
enableCodeExporter
|
|
23
|
+
/>
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import GraphQLPlayground from '..';
|
|
2
|
+
|
|
3
|
+
const betaQuery = `{
|
|
4
|
+
getChainInfo {
|
|
5
|
+
code
|
|
6
|
+
info {
|
|
7
|
+
network
|
|
8
|
+
moniker
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}`;
|
|
12
|
+
|
|
13
|
+
export default function WithCodeExporter() {
|
|
14
|
+
return (
|
|
15
|
+
<div style={{ minWidth: '1280px', height: '40vh', border: '1px solid #EEE', marginTop: '16px' }}>
|
|
16
|
+
<GraphQLPlayground
|
|
17
|
+
defaultQuery={betaQuery}
|
|
18
|
+
endpoint="https://beta.abtnetwork.io/api/"
|
|
19
|
+
title="Beta Chain"
|
|
20
|
+
enableQueryComposer={false}
|
|
21
|
+
enableCodeExporter
|
|
22
|
+
/>
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import GraphQLPlayground from '..';
|
|
2
|
+
|
|
3
|
+
const betaQuery = `{
|
|
4
|
+
getChainInfo {
|
|
5
|
+
code
|
|
6
|
+
info {
|
|
7
|
+
network
|
|
8
|
+
moniker
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}`;
|
|
12
|
+
|
|
13
|
+
export default function WithHistory() {
|
|
14
|
+
return (
|
|
15
|
+
<div style={{ width: '1280px', height: '40vh', border: '1px solid #EEE' }}>
|
|
16
|
+
<GraphQLPlayground
|
|
17
|
+
defaultQuery={betaQuery}
|
|
18
|
+
endpoint="https://beta.abtnetwork.io/api/"
|
|
19
|
+
title="Beta Chain"
|
|
20
|
+
enableQueryComposer={false}
|
|
21
|
+
enableHistory
|
|
22
|
+
/>
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import GraphQLPlayground from '..';
|
|
2
|
+
|
|
3
|
+
const betaQuery = `{
|
|
4
|
+
getChainInfo {
|
|
5
|
+
code
|
|
6
|
+
info {
|
|
7
|
+
network
|
|
8
|
+
moniker
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}`;
|
|
12
|
+
|
|
13
|
+
export default function WithQueryComposer() {
|
|
14
|
+
return (
|
|
15
|
+
<div style={{ minWidth: '1280px', height: '40vh', border: '1px solid #EEE' }}>
|
|
16
|
+
<GraphQLPlayground
|
|
17
|
+
defaultQuery={betaQuery}
|
|
18
|
+
endpoint="https://beta.abtnetwork.io/api/"
|
|
19
|
+
title="Beta Chain"
|
|
20
|
+
enableQueryComposer
|
|
21
|
+
/>
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
}
|
package/src/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import GraphiQL from 'graphiql';
|
|
|
10
10
|
import QueryComposer from 'graphiql-explorer';
|
|
11
11
|
import CodeExporter from 'graphiql-code-exporter';
|
|
12
12
|
import CodeExporterSnippets from 'graphiql-code-exporter/lib/snippets';
|
|
13
|
-
import { buildClientSchema, getIntrospectionQuery
|
|
13
|
+
import { buildClientSchema, getIntrospectionQuery } from 'graphql';
|
|
14
14
|
import { useHistoryContext, usePrettifyEditors } from '@graphiql/react';
|
|
15
15
|
|
|
16
16
|
import { useHistory } from 'react-router-dom';
|
|
@@ -69,60 +69,6 @@ export default function GraphQLPlayground(props) {
|
|
|
69
69
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
70
70
|
}, []);
|
|
71
71
|
|
|
72
|
-
const onInspect = (cm, mousePos) => {
|
|
73
|
-
const parsedQuery = parse(query || '');
|
|
74
|
-
|
|
75
|
-
if (!parsedQuery) {
|
|
76
|
-
// eslint-disable-next-line quotes
|
|
77
|
-
console.error("Couldn't parse query document");
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const token = cm.getTokenAt(mousePos);
|
|
82
|
-
const start = { line: mousePos.line, ch: token.start };
|
|
83
|
-
const end = { line: mousePos.line, ch: token.end };
|
|
84
|
-
const relevantMousePos = {
|
|
85
|
-
start: cm.indexFromPos(start),
|
|
86
|
-
end: cm.indexFromPos(end),
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const position = relevantMousePos;
|
|
90
|
-
|
|
91
|
-
const def = parsedQuery.definitions.find((definition) => {
|
|
92
|
-
if (!definition.loc) {
|
|
93
|
-
// eslint-disable-next-line no-console
|
|
94
|
-
console.log('Missing location information for definition');
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// eslint-disable-next-line no-shadow
|
|
99
|
-
const { start, end } = definition.loc;
|
|
100
|
-
return start <= position.start && end >= position.end;
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
if (!def) {
|
|
104
|
-
console.error('Unable to find definition corresponding to mouse position');
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const operationKind =
|
|
109
|
-
def.kind === 'OperationDefinition' ? def.operation : def.kind === 'FragmentDefinition' ? 'fragment' : 'unknown';
|
|
110
|
-
|
|
111
|
-
const operationName =
|
|
112
|
-
def.kind === 'OperationDefinition' && !!def.name
|
|
113
|
-
? def.name.value
|
|
114
|
-
: def.kind === 'FragmentDefinition' && !!def.name
|
|
115
|
-
? def.name.value
|
|
116
|
-
: 'unknown';
|
|
117
|
-
|
|
118
|
-
const selector = `.graphiql-explorer-root #${operationKind}-${operationName}`;
|
|
119
|
-
|
|
120
|
-
const element = document.querySelector(selector);
|
|
121
|
-
if (element) {
|
|
122
|
-
element.scrollIntoView();
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
72
|
const onEditQuery = (newQuery) => {
|
|
127
73
|
if (newQuery !== query && newProps.persistentQuery) {
|
|
128
74
|
persistQuery(newQuery);
|
|
@@ -193,13 +139,6 @@ export default function GraphQLPlayground(props) {
|
|
|
193
139
|
if (!graphiql.current) {
|
|
194
140
|
return;
|
|
195
141
|
}
|
|
196
|
-
|
|
197
|
-
const editor = graphiql.current.getQueryEditor();
|
|
198
|
-
editor.setOption('extraKeys', {
|
|
199
|
-
...(editor.options.extraKeys || {}),
|
|
200
|
-
'Shift-Alt-LeftClick': onInspect,
|
|
201
|
-
});
|
|
202
|
-
|
|
203
142
|
setSchema(buildClientSchema(result.data));
|
|
204
143
|
});
|
|
205
144
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|