@arcblock/graphql-playground 2.13.69 → 3.0.0
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/README.md +1 -1
- package/lib/index.js +227 -212
- package/lib/util.js +23 -44
- package/package.json +13 -20
- package/src/GraphqlPlayground.stories.jsx +16 -0
- package/src/index.jsx +275 -0
- package/vite.config.mjs +29 -0
- package/src/index.js +0 -404
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ module.exports = graphiql;
|
|
|
60
60
|
Then, in `gatsby-node.js`, use the mocks:
|
|
61
61
|
|
|
62
62
|
```javascript
|
|
63
|
-
const path = require('path');
|
|
63
|
+
const path = require('node:path');
|
|
64
64
|
|
|
65
65
|
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
|
|
66
66
|
if (stage === 'build-html') {
|
package/lib/index.js
CHANGED
|
@@ -1,222 +1,237 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
36
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
37
|
-
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
38
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
39
|
-
function HistoryToggleButton() {
|
|
40
|
-
const {
|
|
41
|
-
toggle
|
|
42
|
-
} = (0, _react2.useHistoryContext)();
|
|
43
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_graphiql.default.Button, {
|
|
44
|
-
onClick: toggle,
|
|
45
|
-
label: "History",
|
|
46
|
-
title: "Show History"
|
|
47
|
-
});
|
|
1
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import o from "prop-types";
|
|
3
|
+
import { styled as x } from "@arcblock/ux/lib/Theme";
|
|
4
|
+
import { GraphiQL as h } from "graphiql";
|
|
5
|
+
import { explorerPlugin as m } from "@graphiql/plugin-explorer";
|
|
6
|
+
import { createGraphiQLFetcher as g } from "@graphiql/toolkit";
|
|
7
|
+
import t from "lodash/isUndefined";
|
|
8
|
+
import "graphiql/style.css";
|
|
9
|
+
import "@graphiql/plugin-explorer/style.css";
|
|
10
|
+
import { mergeProps as b } from "@arcblock/ux/lib/Util";
|
|
11
|
+
function a(e) {
|
|
12
|
+
const r = Object.assign({}, e);
|
|
13
|
+
t(r.title) && (r.title = "Query"), t(r.defaultQuery) && (r.defaultQuery = "{}"), t(r.persistentQuery) && (r.persistentQuery = !1), t(r.enableQueryComposer) && (r.enableQueryComposer = !0), t(r.enableCodeExporter) && (r.enableCodeExporter = !1), t(r.enableHistory) && (r.enableHistory = !1), t(r.extraCodeSnippets) && (r.extraCodeSnippets = []), t(r.extraHeaders) && (r.extraHeaders = {});
|
|
14
|
+
const p = b(r, a, [
|
|
15
|
+
"style",
|
|
16
|
+
"persistentQuery",
|
|
17
|
+
"enableQueryComposer",
|
|
18
|
+
"enableCodeExporter",
|
|
19
|
+
"enableHistory"
|
|
20
|
+
]), n = g({
|
|
21
|
+
url: p.endpoint
|
|
22
|
+
}), l = [m()], {
|
|
23
|
+
endpoint: y,
|
|
24
|
+
title: f,
|
|
25
|
+
enableCodeExporter: C,
|
|
26
|
+
enableQueryComposer: w,
|
|
27
|
+
enableHistory: $,
|
|
28
|
+
extraCodeSnippets: Q,
|
|
29
|
+
defaultQuery: d,
|
|
30
|
+
extraHeaders: k,
|
|
31
|
+
persistentQuery: H,
|
|
32
|
+
...s
|
|
33
|
+
} = p;
|
|
34
|
+
return /* @__PURE__ */ i(c, { ...s, children: /* @__PURE__ */ i(h, { fetcher: n, plugins: l, defaultQuery: d }) });
|
|
48
35
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
36
|
+
a.propTypes = {
|
|
37
|
+
endpoint: o.string.isRequired,
|
|
38
|
+
defaultQuery: o.string,
|
|
39
|
+
title: o.string,
|
|
40
|
+
persistentQuery: o.bool,
|
|
41
|
+
enableQueryComposer: o.bool,
|
|
42
|
+
enableCodeExporter: o.bool,
|
|
43
|
+
enableHistory: o.bool,
|
|
44
|
+
extraCodeSnippets: o.array,
|
|
45
|
+
extraHeaders: o.any
|
|
46
|
+
};
|
|
47
|
+
const c = x("div")`
|
|
48
|
+
display: flex;
|
|
49
|
+
flex-direction: row;
|
|
50
|
+
flex: 1;
|
|
51
|
+
overflow: hidden;
|
|
52
|
+
height: 100%;
|
|
53
|
+
position: relative;
|
|
54
|
+
|
|
55
|
+
@media (max-width: ${(e) => e.theme.breakpoints.values.md}px) {
|
|
56
|
+
margin-top: 30px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
> .historyPaneWrap {
|
|
60
|
+
z-index: 8 !important;
|
|
61
|
+
width: 320px !important;
|
|
62
|
+
box-shadow: 5px 16px 10px 0 rgba(0, 0, 0, ${(e) => e.theme.mode === "light" ? 0.05 : 0.5});
|
|
63
|
+
overflow-y: scroll;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.doc-explorer-title-bar,
|
|
67
|
+
.history-title-bar {
|
|
68
|
+
height: 45px;
|
|
69
|
+
line-height: 45px;
|
|
70
|
+
padding: 0px 8px;
|
|
71
|
+
display: flex;
|
|
72
|
+
align-items: center;
|
|
73
|
+
justify-content: space-between;
|
|
74
|
+
}
|
|
75
|
+
.doc-explorer-title-bar {
|
|
76
|
+
padding: 0px 32px;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.doc-explorer-title,
|
|
80
|
+
.history-title {
|
|
81
|
+
font-size: 14px;
|
|
82
|
+
font-weight: 900;
|
|
83
|
+
letter-spacing: 2px;
|
|
84
|
+
color: ${(e) => e.theme.typography.color.gray};
|
|
85
|
+
text-transform: uppercase;
|
|
86
|
+
text-align: left !important;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.doc-explorer-contents {
|
|
90
|
+
min-height: 0;
|
|
91
|
+
}
|
|
92
|
+
.history-contents {
|
|
93
|
+
top: 45px !important;
|
|
94
|
+
background-color: ${(e) => e.theme.palette.background.default} !important;
|
|
95
|
+
border-top: 1px solid #e3e3e3 !important;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.history-contents {
|
|
99
|
+
color: ${(e) => e.theme.typography.color.main};
|
|
100
|
+
p {
|
|
101
|
+
border-bottom: 1px solid #e3e3e3;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.docExplorerHide {
|
|
106
|
+
color: ${(e) => e.theme.typography.color.main};
|
|
107
|
+
padding: 0;
|
|
108
|
+
cursor: pointer;
|
|
109
|
+
margin: -7px -8px -6px -12px;
|
|
110
|
+
opacity: 0.75;
|
|
111
|
+
font-size: 18px;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.toolbar-button {
|
|
115
|
+
cursor: pointer;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.graphiql-container {
|
|
119
|
+
.title {
|
|
120
|
+
color: ${(e) => e.theme.typography.color.main};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.topBar {
|
|
124
|
+
background-image: none;
|
|
125
|
+
height: 45px;
|
|
126
|
+
border-bottom-width: 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.docExplorerShow {
|
|
130
|
+
background: ${(e) => e.theme.palette.background.default};
|
|
131
|
+
border: none;
|
|
132
|
+
font-size: 14px;
|
|
133
|
+
color: ${(e) => e.theme.typography.color.main};
|
|
134
|
+
text-transform: uppercase;
|
|
135
|
+
|
|
136
|
+
&::before {
|
|
137
|
+
border-color: ${(e) => e.theme.typography.color.gray};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.historyPaneWrap {
|
|
142
|
+
width: 320px !important;
|
|
143
|
+
background-color: ${(e) => e.theme.palette.background.default};
|
|
144
|
+
box-shadow: 5px 16px 10px 0 rgba(0, 0, 0, ${(e) => e.theme.mode === "light" ? 0.05 : 0.5});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.search-box {
|
|
148
|
+
margin-bottom: 20px;
|
|
149
|
+
border-bottom: none;
|
|
150
|
+
|
|
151
|
+
input {
|
|
152
|
+
height: 30px;
|
|
153
|
+
border-radius: 15px;
|
|
154
|
+
border: solid 1px ${(e) => e.theme.typography.color.main};
|
|
155
|
+
padding: 6px 24px 8px 30px;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.search-box-clear {
|
|
159
|
+
right: 10px;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
&::before {
|
|
163
|
+
left: 10px;
|
|
84
164
|
}
|
|
85
165
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
166
|
+
|
|
167
|
+
.variable-editor-title {
|
|
168
|
+
background: ${(e) => e.theme.palette.background.default};
|
|
169
|
+
border: none;
|
|
170
|
+
height: 40px;
|
|
171
|
+
padding-left: 20px;
|
|
172
|
+
|
|
173
|
+
&::before {
|
|
174
|
+
border-left: 2px solid ${(e) => e.theme.typography.color.gray};
|
|
175
|
+
border-top: 2px solid ${(e) => e.theme.typography.color.gray};
|
|
176
|
+
content: '';
|
|
177
|
+
display: inline-block;
|
|
178
|
+
height: 9px;
|
|
179
|
+
margin: 0 5px 1px 0;
|
|
180
|
+
position: relative;
|
|
181
|
+
-webkit-transform: rotate(-135deg);
|
|
182
|
+
transform: rotate(-135deg);
|
|
183
|
+
width: 9px;
|
|
184
|
+
}
|
|
91
185
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
subscriptionClient.current = null;
|
|
186
|
+
|
|
187
|
+
.resultWrap {
|
|
188
|
+
border-left: none;
|
|
189
|
+
.CodeMirror-gutters {
|
|
190
|
+
opacity: 0.5;
|
|
191
|
+
}
|
|
192
|
+
.CodeMirror-gutter.CodeMirror-foldgutter {
|
|
193
|
+
box-shadow: 5px 16px 10px 0 rgba(0, 0, 0, ${(e) => e.theme.mode === "light" ? 0.05 : 0.5});
|
|
194
|
+
}
|
|
102
195
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
196
|
+
|
|
197
|
+
.CodeMirror,
|
|
198
|
+
.CodeMirror-gutters,
|
|
199
|
+
.CodeMirror-linenumber,
|
|
200
|
+
.CodeMirror-foldgutter {
|
|
201
|
+
background: ${(e) => e.theme.palette.background.default};
|
|
109
202
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
};
|
|
115
|
-
const httpFetcher = async params => {
|
|
116
|
-
const extraHeaders = typeof newProps.extraHeaders === 'function' ? newProps.extraHeaders() : newProps.extraHeaders || {};
|
|
117
|
-
const res = await (0, _axios.default)({
|
|
118
|
-
method: 'post',
|
|
119
|
-
url: newProps.endpoint,
|
|
120
|
-
data: params,
|
|
121
|
-
headers: Object.assign({
|
|
122
|
-
'Content-Type': 'application/json'
|
|
123
|
-
}, extraHeaders)
|
|
124
|
-
});
|
|
125
|
-
return res.data;
|
|
126
|
-
};
|
|
127
|
-
const fetcher = params => {
|
|
128
|
-
if (params.query.indexOf('subscription') >= 0) {
|
|
129
|
-
ensureSubscriptionClient();
|
|
130
|
-
|
|
131
|
-
// disable subscription in test env
|
|
132
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
133
|
-
return (0, _util.graphQLFetcher)(subscriptionClient.current, httpFetcher)(params);
|
|
203
|
+
|
|
204
|
+
.variable-editor {
|
|
205
|
+
.CodeMirror {
|
|
206
|
+
background: white;
|
|
134
207
|
}
|
|
135
208
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
209
|
+
|
|
210
|
+
.CodeMirror-gutters {
|
|
211
|
+
border-right-width: 0;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.graphiql-exporter-container {
|
|
216
|
+
width: auto;
|
|
217
|
+
.historyPaneWrap {
|
|
218
|
+
position: absolute !important;
|
|
219
|
+
height: 100%;
|
|
220
|
+
top: 0;
|
|
221
|
+
right: 0;
|
|
222
|
+
background-color: ${(e) => e.theme.palette.background.default};
|
|
223
|
+
box-shadow: -5px 16px 10px 0 rgba(0, 0, 0, ${(e) => e.theme.mode === "light" ? 0.05 : 0.5});
|
|
224
|
+
z-index: 3;
|
|
225
|
+
|
|
226
|
+
.history-contents {
|
|
227
|
+
padding-top: 12px;
|
|
228
|
+
.toolbar-button {
|
|
229
|
+
margin-top: -24px !important;
|
|
230
|
+
}
|
|
144
231
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
endpoint,
|
|
151
|
-
title,
|
|
152
|
-
enableCodeExporter,
|
|
153
|
-
enableQueryComposer,
|
|
154
|
-
enableHistory,
|
|
155
|
-
extraCodeSnippets
|
|
156
|
-
} = newProps,
|
|
157
|
-
rest = _objectWithoutProperties(newProps, _excluded);
|
|
158
|
-
const snippets = [...extraCodeSnippets, ..._snippets.default];
|
|
159
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Container, _objectSpread(_objectSpread({}, rest), {}, {
|
|
160
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactLoadScript.default, {
|
|
161
|
-
url: "//cdn.jsdelivr.net/npm/@absinthe/socket-graphiql@0.2.1/compat/umd/index.js"
|
|
162
|
-
}), enableQueryComposer && /*#__PURE__*/(0, _jsxRuntime.jsx)(_graphiqlExplorer.default, {
|
|
163
|
-
schema: schema,
|
|
164
|
-
query: query,
|
|
165
|
-
onEdit: onEditQuery,
|
|
166
|
-
onRunOperation: operationName => graphiql.current.handleRunQuery(operationName),
|
|
167
|
-
explorerIsOpen: queryComposerIsOpen,
|
|
168
|
-
onToggleExplorer: onToggleExplorer,
|
|
169
|
-
className: "graphiql-explorer"
|
|
170
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_graphiql.default, {
|
|
171
|
-
ref: graphiql,
|
|
172
|
-
fetcher: fetcher,
|
|
173
|
-
schema: schema,
|
|
174
|
-
query: query,
|
|
175
|
-
onEditQuery: onEditQuery,
|
|
176
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_graphiql.default.Logo, {
|
|
177
|
-
children: title
|
|
178
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_graphiql.default.Toolbar, {
|
|
179
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(PrettifyButton, {}), enableHistory && /*#__PURE__*/(0, _jsxRuntime.jsx)(HistoryToggleButton, {}), enableQueryComposer && /*#__PURE__*/(0, _jsxRuntime.jsx)(_graphiql.default.Button, {
|
|
180
|
-
onClick: onToggleExplorer,
|
|
181
|
-
label: "Query Composer",
|
|
182
|
-
title: "Toggle Query Composer"
|
|
183
|
-
}), enableCodeExporter && /*#__PURE__*/(0, _jsxRuntime.jsx)(_graphiql.default.Button, {
|
|
184
|
-
onClick: onToggleCodeExporter,
|
|
185
|
-
label: "Code Exporter",
|
|
186
|
-
title: "Toggle Code Exporter"
|
|
187
|
-
})]
|
|
188
|
-
})]
|
|
189
|
-
}), enableCodeExporter && codeExporterIsOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
190
|
-
className: "graphiql-container graphiql-exporter-container",
|
|
191
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_graphiqlCodeExporter.default, {
|
|
192
|
-
hideCodeExporter: onToggleCodeExporter,
|
|
193
|
-
snippets: snippets,
|
|
194
|
-
serverUrl: endpoint,
|
|
195
|
-
query: query,
|
|
196
|
-
codeMirrorTheme: "neo"
|
|
197
|
-
})
|
|
198
|
-
})]
|
|
199
|
-
}));
|
|
200
|
-
}
|
|
201
|
-
GraphQLPlayground.propTypes = {
|
|
202
|
-
endpoint: _propTypes.default.string.isRequired,
|
|
203
|
-
defaultQuery: _propTypes.default.string,
|
|
204
|
-
title: _propTypes.default.string,
|
|
205
|
-
persistentQuery: _propTypes.default.bool,
|
|
206
|
-
enableQueryComposer: _propTypes.default.bool,
|
|
207
|
-
enableCodeExporter: _propTypes.default.bool,
|
|
208
|
-
enableHistory: _propTypes.default.bool,
|
|
209
|
-
extraCodeSnippets: _propTypes.default.array,
|
|
210
|
-
extraHeaders: _propTypes.default.any
|
|
211
|
-
};
|
|
212
|
-
GraphQLPlayground.defaultProps = {
|
|
213
|
-
title: 'Query',
|
|
214
|
-
defaultQuery: '{}',
|
|
215
|
-
persistentQuery: false,
|
|
216
|
-
enableQueryComposer: true,
|
|
217
|
-
enableCodeExporter: false,
|
|
218
|
-
enableHistory: false,
|
|
219
|
-
extraCodeSnippets: [],
|
|
220
|
-
extraHeaders: {}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
`;
|
|
235
|
+
export {
|
|
236
|
+
a as default
|
|
221
237
|
};
|
|
222
|
-
const Container = (0, _Theme.styled)('div')(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: row;\n flex: 1;\n overflow: hidden;\n height: 100%;\n position: relative;\n\n @media (max-width: ", "px) {\n margin-top: 30px;\n }\n\n > .historyPaneWrap {\n z-index: 8 !important;\n width: 320px !important;\n box-shadow: 5px 16px 10px 0 rgba(0, 0, 0, ", ");\n overflow-y: scroll;\n }\n\n .doc-explorer-title-bar,\n .history-title-bar {\n height: 45px;\n line-height: 45px;\n padding: 0px 8px;\n display: flex;\n align-items: center;\n justify-content: space-between;\n }\n .doc-explorer-title-bar {\n padding: 0px 32px;\n }\n\n .doc-explorer-title,\n .history-title {\n font-size: 14px;\n font-weight: 900;\n letter-spacing: 2px;\n color: ", ";\n text-transform: uppercase;\n text-align: left !important;\n }\n\n .doc-explorer-contents {\n min-height: 0;\n }\n .history-contents {\n top: 45px !important;\n background-color: ", " !important;\n border-top: 1px solid #e3e3e3 !important;\n }\n\n .history-contents {\n color: ", ";\n p {\n border-bottom: 1px solid #e3e3e3;\n }\n }\n\n .docExplorerHide {\n color: ", ";\n padding: 0;\n cursor: pointer;\n margin: -7px -8px -6px -12px;\n opacity: 0.75;\n font-size: 18px;\n }\n\n .toolbar-button {\n cursor: pointer;\n }\n\n .graphiql-container {\n .title {\n color: ", ";\n }\n\n .topBar {\n background-image: none;\n height: 45px;\n border-bottom-width: 0;\n }\n\n .docExplorerShow {\n background: ", ";\n border: none;\n font-size: 14px;\n color: ", ";\n text-transform: uppercase;\n\n &::before {\n border-color: ", ";\n }\n }\n\n .historyPaneWrap {\n width: 320px !important;\n background-color: ", ";\n box-shadow: 5px 16px 10px 0 rgba(0, 0, 0, ", ");\n }\n\n .search-box {\n margin-bottom: 20px;\n border-bottom: none;\n\n input {\n height: 30px;\n border-radius: 15px;\n border: solid 1px ", ";\n padding: 6px 24px 8px 30px;\n }\n\n .search-box-clear {\n right: 10px;\n }\n\n &::before {\n left: 10px;\n }\n }\n\n .variable-editor-title {\n background: ", ";\n border: none;\n height: 40px;\n padding-left: 20px;\n\n &::before {\n border-left: 2px solid ", ";\n border-top: 2px solid ", ";\n content: '';\n display: inline-block;\n height: 9px;\n margin: 0 5px 1px 0;\n position: relative;\n -webkit-transform: rotate(-135deg);\n transform: rotate(-135deg);\n width: 9px;\n }\n }\n\n .resultWrap {\n border-left: none;\n .CodeMirror-gutters {\n opacity: 0.5;\n }\n .CodeMirror-gutter.CodeMirror-foldgutter {\n box-shadow: 5px 16px 10px 0 rgba(0, 0, 0, ", ");\n }\n }\n\n .CodeMirror,\n .CodeMirror-gutters,\n .CodeMirror-linenumber,\n .CodeMirror-foldgutter {\n background: ", ";\n }\n\n .variable-editor {\n .CodeMirror {\n background: white;\n }\n }\n\n .CodeMirror-gutters {\n border-right-width: 0;\n }\n }\n\n .graphiql-exporter-container {\n width: auto;\n .historyPaneWrap {\n position: absolute !important;\n height: 100%;\n top: 0;\n right: 0;\n background-color: ", ";\n box-shadow: -5px 16px 10px 0 rgba(0, 0, 0, ", ");\n z-index: 3;\n\n .history-contents {\n padding-top: 12px;\n .toolbar-button {\n margin-top: -24px !important;\n }\n }\n }\n }\n"])), props => props.theme.breakpoints.values.md, props => props.theme.mode === 'light' ? 0.05 : 0.5, props => props.theme.typography.color.gray, props => props.theme.palette.background.default, props => props.theme.typography.color.main, props => props.theme.typography.color.main, props => props.theme.typography.color.main, props => props.theme.palette.background.default, props => props.theme.typography.color.main, props => props.theme.typography.color.gray, props => props.theme.palette.background.default, props => props.theme.mode === 'light' ? 0.05 : 0.5, props => props.theme.typography.color.main, props => props.theme.palette.background.default, props => props.theme.typography.color.gray, props => props.theme.typography.color.gray, props => props.theme.mode === 'light' ? 0.05 : 0.5, props => props.theme.palette.background.default, props => props.theme.palette.background.default, props => props.theme.mode === 'light' ? 0.05 : 0.5);
|
package/lib/util.js
CHANGED
|
@@ -1,47 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
21
|
-
const graphQLFetcher = (subscriptionsClient, fallbackFetcher) => {
|
|
22
|
-
let activeSubscriptionId = null;
|
|
23
|
-
return params => {
|
|
24
|
-
if (subscriptionsClient && activeSubscriptionId !== null) {
|
|
25
|
-
subscriptionsClient.unsubscribe(activeSubscriptionId);
|
|
26
|
-
}
|
|
27
|
-
if (subscriptionsClient && hasSubscriptionOperation(params)) {
|
|
28
|
-
return {
|
|
29
|
-
subscribe(observer) {
|
|
30
|
-
observer.next('Your subscription data will appear here after server publication!');
|
|
31
|
-
activeSubscriptionId = subscriptionsClient.subscribe({
|
|
32
|
-
query: params.query,
|
|
33
|
-
variables: params.variables
|
|
34
|
-
}, (error, result) => {
|
|
35
|
-
if (error) {
|
|
36
|
-
observer.error(error);
|
|
37
|
-
} else {
|
|
38
|
-
observer.next(result);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
1
|
+
import { parse as f } from "graphql";
|
|
2
|
+
const a = (e) => {
|
|
3
|
+
const t = f(e.query);
|
|
4
|
+
for (const r of t.definitions)
|
|
5
|
+
if (r.kind === "OperationDefinition" && r.operation === "subscription")
|
|
6
|
+
return !0;
|
|
7
|
+
return !1;
|
|
8
|
+
}, s = (e, t) => {
|
|
9
|
+
let r = null;
|
|
10
|
+
return (i) => (e && r !== null && e.unsubscribe(r), e && a(i) ? {
|
|
11
|
+
subscribe(n) {
|
|
12
|
+
n.next("Your subscription data will appear here after server publication!"), r = e.subscribe(
|
|
13
|
+
{
|
|
14
|
+
query: i.query,
|
|
15
|
+
variables: i.variables
|
|
16
|
+
},
|
|
17
|
+
(u, o) => {
|
|
18
|
+
u ? n.error(u) : n.next(o);
|
|
41
19
|
}
|
|
42
|
-
|
|
20
|
+
);
|
|
43
21
|
}
|
|
44
|
-
|
|
45
|
-
|
|
22
|
+
} : t(i));
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
s as graphQLFetcher
|
|
46
26
|
};
|
|
47
|
-
exports.graphQLFetcher = graphQLFetcher;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/graphql-playground",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "A React Component to interact with GraphQL APIs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"lint": "eslint src tests --ext js --ext jsx",
|
|
20
20
|
"lint:fix": "npm run lint -- --fix",
|
|
21
|
-
"build": "
|
|
22
|
-
"watch": "
|
|
21
|
+
"build": "vite build",
|
|
22
|
+
"watch": "vite build --watch",
|
|
23
23
|
"precommit": "CI=1 npm run lint",
|
|
24
24
|
"prepush": "CI=1 npm run lint",
|
|
25
25
|
"prepublish": "npm run build",
|
|
@@ -30,31 +30,24 @@
|
|
|
30
30
|
"url": "https://github.com/ArcBlock/ux/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"graphiql": "^1.
|
|
36
|
-
"
|
|
37
|
-
"graphiql-explorer": "^0.9.0",
|
|
38
|
-
"graphql": "^16.6.0",
|
|
39
|
-
"react-load-script": "^0.0.6"
|
|
33
|
+
"@graphiql/plugin-explorer": "^4.0.6",
|
|
34
|
+
"axios": "^1.10.0",
|
|
35
|
+
"graphiql": "^4.1.2",
|
|
36
|
+
"graphql": "^16.11.0"
|
|
40
37
|
},
|
|
41
38
|
"peerDependencies": {
|
|
42
|
-
"@arcblock/ux": "
|
|
43
|
-
"@emotion/react": "^11.
|
|
44
|
-
"@emotion/styled": "^11.
|
|
45
|
-
"react": "^
|
|
39
|
+
"@arcblock/ux": "workspace:*",
|
|
40
|
+
"@emotion/react": "^11.14.0",
|
|
41
|
+
"@emotion/styled": "^11.14.0",
|
|
42
|
+
"react": "^19.0.0",
|
|
46
43
|
"react-router-dom": "^6.22.3"
|
|
47
44
|
},
|
|
48
45
|
"publishConfig": {
|
|
49
46
|
"access": "public"
|
|
50
47
|
},
|
|
51
48
|
"devDependencies": {
|
|
52
|
-
"
|
|
53
|
-
"@babel/core": "^7.19.3",
|
|
54
|
-
"@babel/preset-env": "^7.19.3",
|
|
55
|
-
"@babel/preset-react": "^7.18.6",
|
|
56
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
49
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
57
50
|
"jest": "^29.7.0"
|
|
58
51
|
},
|
|
59
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "b001c32ca85d40d8a0784ca581bfd54d90550b24"
|
|
60
53
|
}
|
|
@@ -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: 'Data Display/GraphQLPlayground',
|
|
9
|
+
parameters: {
|
|
10
|
+
docs: {
|
|
11
|
+
description: {
|
|
12
|
+
component: 'A GraphQL Playground component built on top of `graphql/graphiql`',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
package/src/index.jsx
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import { styled } from '@arcblock/ux/lib/Theme';
|
|
3
|
+
import { GraphiQL } from 'graphiql';
|
|
4
|
+
// eslint-disable-next-line import/no-unresolved
|
|
5
|
+
import { explorerPlugin } from '@graphiql/plugin-explorer';
|
|
6
|
+
import { createGraphiQLFetcher } from '@graphiql/toolkit';
|
|
7
|
+
import isUndefined from 'lodash/isUndefined';
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line import/no-unresolved
|
|
10
|
+
import 'graphiql/style.css';
|
|
11
|
+
// eslint-disable-next-line import/no-unresolved
|
|
12
|
+
import '@graphiql/plugin-explorer/style.css';
|
|
13
|
+
|
|
14
|
+
import { mergeProps } from '@arcblock/ux/lib/Util';
|
|
15
|
+
|
|
16
|
+
export default function GraphQLPlayground(rawProps) {
|
|
17
|
+
const props = Object.assign({}, rawProps);
|
|
18
|
+
if (isUndefined(props.title)) {
|
|
19
|
+
props.title = 'Query';
|
|
20
|
+
}
|
|
21
|
+
if (isUndefined(props.defaultQuery)) {
|
|
22
|
+
props.defaultQuery = '{}';
|
|
23
|
+
}
|
|
24
|
+
if (isUndefined(props.persistentQuery)) {
|
|
25
|
+
props.persistentQuery = false;
|
|
26
|
+
}
|
|
27
|
+
if (isUndefined(props.enableQueryComposer)) {
|
|
28
|
+
props.enableQueryComposer = true;
|
|
29
|
+
}
|
|
30
|
+
if (isUndefined(props.enableCodeExporter)) {
|
|
31
|
+
props.enableCodeExporter = false;
|
|
32
|
+
}
|
|
33
|
+
if (isUndefined(props.enableHistory)) {
|
|
34
|
+
props.enableHistory = false;
|
|
35
|
+
}
|
|
36
|
+
if (isUndefined(props.extraCodeSnippets)) {
|
|
37
|
+
props.extraCodeSnippets = [];
|
|
38
|
+
}
|
|
39
|
+
if (isUndefined(props.extraHeaders)) {
|
|
40
|
+
props.extraHeaders = {};
|
|
41
|
+
}
|
|
42
|
+
const newProps = mergeProps(props, GraphQLPlayground, [
|
|
43
|
+
'style',
|
|
44
|
+
'persistentQuery',
|
|
45
|
+
'enableQueryComposer',
|
|
46
|
+
'enableCodeExporter',
|
|
47
|
+
'enableHistory',
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
const fetcher = createGraphiQLFetcher({
|
|
51
|
+
url: newProps.endpoint,
|
|
52
|
+
});
|
|
53
|
+
const explorer = explorerPlugin();
|
|
54
|
+
const plugins = [explorer];
|
|
55
|
+
|
|
56
|
+
const {
|
|
57
|
+
endpoint,
|
|
58
|
+
title,
|
|
59
|
+
enableCodeExporter,
|
|
60
|
+
enableQueryComposer,
|
|
61
|
+
enableHistory,
|
|
62
|
+
extraCodeSnippets,
|
|
63
|
+
defaultQuery,
|
|
64
|
+
extraHeaders,
|
|
65
|
+
persistentQuery,
|
|
66
|
+
...rest
|
|
67
|
+
} = newProps;
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<Container {...rest}>
|
|
71
|
+
<GraphiQL fetcher={fetcher} plugins={plugins} defaultQuery={defaultQuery} />
|
|
72
|
+
</Container>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
GraphQLPlayground.propTypes = {
|
|
77
|
+
endpoint: PropTypes.string.isRequired,
|
|
78
|
+
defaultQuery: PropTypes.string,
|
|
79
|
+
title: PropTypes.string,
|
|
80
|
+
persistentQuery: PropTypes.bool,
|
|
81
|
+
enableQueryComposer: PropTypes.bool,
|
|
82
|
+
enableCodeExporter: PropTypes.bool,
|
|
83
|
+
enableHistory: PropTypes.bool,
|
|
84
|
+
extraCodeSnippets: PropTypes.array,
|
|
85
|
+
extraHeaders: PropTypes.any,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const Container = styled('div')`
|
|
89
|
+
display: flex;
|
|
90
|
+
flex-direction: row;
|
|
91
|
+
flex: 1;
|
|
92
|
+
overflow: hidden;
|
|
93
|
+
height: 100%;
|
|
94
|
+
position: relative;
|
|
95
|
+
|
|
96
|
+
@media (max-width: ${(props) => props.theme.breakpoints.values.md}px) {
|
|
97
|
+
margin-top: 30px;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
> .historyPaneWrap {
|
|
101
|
+
z-index: 8 !important;
|
|
102
|
+
width: 320px !important;
|
|
103
|
+
box-shadow: 5px 16px 10px 0 rgba(0, 0, 0, ${(props) => (props.theme.mode === 'light' ? 0.05 : 0.5)});
|
|
104
|
+
overflow-y: scroll;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.doc-explorer-title-bar,
|
|
108
|
+
.history-title-bar {
|
|
109
|
+
height: 45px;
|
|
110
|
+
line-height: 45px;
|
|
111
|
+
padding: 0px 8px;
|
|
112
|
+
display: flex;
|
|
113
|
+
align-items: center;
|
|
114
|
+
justify-content: space-between;
|
|
115
|
+
}
|
|
116
|
+
.doc-explorer-title-bar {
|
|
117
|
+
padding: 0px 32px;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.doc-explorer-title,
|
|
121
|
+
.history-title {
|
|
122
|
+
font-size: 14px;
|
|
123
|
+
font-weight: 900;
|
|
124
|
+
letter-spacing: 2px;
|
|
125
|
+
color: ${(props) => props.theme.typography.color.gray};
|
|
126
|
+
text-transform: uppercase;
|
|
127
|
+
text-align: left !important;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.doc-explorer-contents {
|
|
131
|
+
min-height: 0;
|
|
132
|
+
}
|
|
133
|
+
.history-contents {
|
|
134
|
+
top: 45px !important;
|
|
135
|
+
background-color: ${(props) => props.theme.palette.background.default} !important;
|
|
136
|
+
border-top: 1px solid #e3e3e3 !important;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.history-contents {
|
|
140
|
+
color: ${(props) => props.theme.typography.color.main};
|
|
141
|
+
p {
|
|
142
|
+
border-bottom: 1px solid #e3e3e3;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.docExplorerHide {
|
|
147
|
+
color: ${(props) => props.theme.typography.color.main};
|
|
148
|
+
padding: 0;
|
|
149
|
+
cursor: pointer;
|
|
150
|
+
margin: -7px -8px -6px -12px;
|
|
151
|
+
opacity: 0.75;
|
|
152
|
+
font-size: 18px;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.toolbar-button {
|
|
156
|
+
cursor: pointer;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.graphiql-container {
|
|
160
|
+
.title {
|
|
161
|
+
color: ${(props) => props.theme.typography.color.main};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.topBar {
|
|
165
|
+
background-image: none;
|
|
166
|
+
height: 45px;
|
|
167
|
+
border-bottom-width: 0;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.docExplorerShow {
|
|
171
|
+
background: ${(props) => props.theme.palette.background.default};
|
|
172
|
+
border: none;
|
|
173
|
+
font-size: 14px;
|
|
174
|
+
color: ${(props) => props.theme.typography.color.main};
|
|
175
|
+
text-transform: uppercase;
|
|
176
|
+
|
|
177
|
+
&::before {
|
|
178
|
+
border-color: ${(props) => props.theme.typography.color.gray};
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.historyPaneWrap {
|
|
183
|
+
width: 320px !important;
|
|
184
|
+
background-color: ${(props) => props.theme.palette.background.default};
|
|
185
|
+
box-shadow: 5px 16px 10px 0 rgba(0, 0, 0, ${(props) => (props.theme.mode === 'light' ? 0.05 : 0.5)});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.search-box {
|
|
189
|
+
margin-bottom: 20px;
|
|
190
|
+
border-bottom: none;
|
|
191
|
+
|
|
192
|
+
input {
|
|
193
|
+
height: 30px;
|
|
194
|
+
border-radius: 15px;
|
|
195
|
+
border: solid 1px ${(props) => props.theme.typography.color.main};
|
|
196
|
+
padding: 6px 24px 8px 30px;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.search-box-clear {
|
|
200
|
+
right: 10px;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
&::before {
|
|
204
|
+
left: 10px;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.variable-editor-title {
|
|
209
|
+
background: ${(props) => props.theme.palette.background.default};
|
|
210
|
+
border: none;
|
|
211
|
+
height: 40px;
|
|
212
|
+
padding-left: 20px;
|
|
213
|
+
|
|
214
|
+
&::before {
|
|
215
|
+
border-left: 2px solid ${(props) => props.theme.typography.color.gray};
|
|
216
|
+
border-top: 2px solid ${(props) => props.theme.typography.color.gray};
|
|
217
|
+
content: '';
|
|
218
|
+
display: inline-block;
|
|
219
|
+
height: 9px;
|
|
220
|
+
margin: 0 5px 1px 0;
|
|
221
|
+
position: relative;
|
|
222
|
+
-webkit-transform: rotate(-135deg);
|
|
223
|
+
transform: rotate(-135deg);
|
|
224
|
+
width: 9px;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.resultWrap {
|
|
229
|
+
border-left: none;
|
|
230
|
+
.CodeMirror-gutters {
|
|
231
|
+
opacity: 0.5;
|
|
232
|
+
}
|
|
233
|
+
.CodeMirror-gutter.CodeMirror-foldgutter {
|
|
234
|
+
box-shadow: 5px 16px 10px 0 rgba(0, 0, 0, ${(props) => (props.theme.mode === 'light' ? 0.05 : 0.5)});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.CodeMirror,
|
|
239
|
+
.CodeMirror-gutters,
|
|
240
|
+
.CodeMirror-linenumber,
|
|
241
|
+
.CodeMirror-foldgutter {
|
|
242
|
+
background: ${(props) => props.theme.palette.background.default};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.variable-editor {
|
|
246
|
+
.CodeMirror {
|
|
247
|
+
background: white;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.CodeMirror-gutters {
|
|
252
|
+
border-right-width: 0;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.graphiql-exporter-container {
|
|
257
|
+
width: auto;
|
|
258
|
+
.historyPaneWrap {
|
|
259
|
+
position: absolute !important;
|
|
260
|
+
height: 100%;
|
|
261
|
+
top: 0;
|
|
262
|
+
right: 0;
|
|
263
|
+
background-color: ${(props) => props.theme.palette.background.default};
|
|
264
|
+
box-shadow: -5px 16px 10px 0 rgba(0, 0, 0, ${(props) => (props.theme.mode === 'light' ? 0.05 : 0.5)});
|
|
265
|
+
z-index: 3;
|
|
266
|
+
|
|
267
|
+
.history-contents {
|
|
268
|
+
padding-top: 12px;
|
|
269
|
+
.toolbar-button {
|
|
270
|
+
margin-top: -24px !important;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
`;
|
package/vite.config.mjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import svgr from 'vite-plugin-svgr';
|
|
3
|
+
import react from '@vitejs/plugin-react';
|
|
4
|
+
import noBundlePlugin from 'vite-plugin-no-bundle';
|
|
5
|
+
import fg from 'fast-glob';
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
plugins: [
|
|
9
|
+
react({ jsxRuntime: 'automatic' }),
|
|
10
|
+
svgr({
|
|
11
|
+
include: ['**/*.svg', '**/*.svg?react'],
|
|
12
|
+
}),
|
|
13
|
+
noBundlePlugin({
|
|
14
|
+
root: 'src',
|
|
15
|
+
copy: ['**/*.png', '**/*.gif', '**/*.jpg', '**/*.jpeg', '**/*.d.ts'],
|
|
16
|
+
}),
|
|
17
|
+
],
|
|
18
|
+
build: {
|
|
19
|
+
lib: {
|
|
20
|
+
entry: fg.sync('src/**/*.{tsx,ts,jsx,js}', {
|
|
21
|
+
ignore: ['**/stories/**', '**/demo/**', '**/*.d.ts', '**/*.stories.*'],
|
|
22
|
+
}),
|
|
23
|
+
formats: ['es'],
|
|
24
|
+
fileName: (format, entryName) => `${entryName}.js`,
|
|
25
|
+
},
|
|
26
|
+
outDir: 'lib',
|
|
27
|
+
emptyOutDir: true,
|
|
28
|
+
},
|
|
29
|
+
});
|
package/src/index.js
DELETED
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
/* eslint-disable indent */
|
|
2
|
-
/* eslint-disable no-nested-ternary */
|
|
3
|
-
/* eslint-disable no-undef */
|
|
4
|
-
import { useEffect, useState, useRef } from 'react';
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import { styled } from '@arcblock/ux/lib/Theme';
|
|
7
|
-
import axios from 'axios';
|
|
8
|
-
import Script from 'react-load-script';
|
|
9
|
-
import GraphiQL from 'graphiql';
|
|
10
|
-
import QueryComposer from 'graphiql-explorer';
|
|
11
|
-
import CodeExporter from 'graphiql-code-exporter';
|
|
12
|
-
import CodeExporterSnippets from 'graphiql-code-exporter/lib/snippets';
|
|
13
|
-
import { buildClientSchema, getIntrospectionQuery } from 'graphql';
|
|
14
|
-
import { useHistoryContext, usePrettifyEditors } from '@graphiql/react';
|
|
15
|
-
|
|
16
|
-
import { useNavigate, useLocation } from 'react-router-dom';
|
|
17
|
-
import 'graphiql/graphiql.css';
|
|
18
|
-
|
|
19
|
-
import 'graphiql-code-exporter/CodeExporter.css';
|
|
20
|
-
import 'codemirror/theme/neo.css';
|
|
21
|
-
|
|
22
|
-
import { mergeProps, parseQuery, stringifyQuery } from '@arcblock/ux/lib/Util';
|
|
23
|
-
import { graphQLFetcher } from './util';
|
|
24
|
-
|
|
25
|
-
function HistoryToggleButton() {
|
|
26
|
-
const { toggle } = useHistoryContext();
|
|
27
|
-
return <GraphiQL.Button onClick={toggle} label="History" title="Show History" />;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function PrettifyButton() {
|
|
31
|
-
const prettify = usePrettifyEditors();
|
|
32
|
-
return <GraphiQL.Button onClick={prettify} label="Prettify" title="Prettify Query (Shift-Ctrl-P)" />;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export default function GraphQLPlayground(props) {
|
|
36
|
-
const newProps = mergeProps(props, GraphQLPlayground, [
|
|
37
|
-
'style',
|
|
38
|
-
'persistentQuery',
|
|
39
|
-
'enableQueryComposer',
|
|
40
|
-
'enableCodeExporter',
|
|
41
|
-
'enableHistory',
|
|
42
|
-
]);
|
|
43
|
-
|
|
44
|
-
const location = useLocation();
|
|
45
|
-
const navigate = useNavigate();
|
|
46
|
-
const graphiql = useRef(null);
|
|
47
|
-
const subscriptionClient = useRef(null);
|
|
48
|
-
const [schema, setSchema] = useState(null);
|
|
49
|
-
const [query, setQuery] = useState(newProps.defaultQuery || '{}');
|
|
50
|
-
const [queryComposerIsOpen, setComposerOpen] = useState(newProps.enableQueryComposer);
|
|
51
|
-
const [codeExporterIsOpen, setExporterOpen] = useState(false);
|
|
52
|
-
|
|
53
|
-
const persistQuery = (newQuery) => {
|
|
54
|
-
const { pathname, search } = location;
|
|
55
|
-
const params = parseQuery(search);
|
|
56
|
-
params.query = newQuery;
|
|
57
|
-
const newUrl = `${pathname}?${stringifyQuery(params)}`;
|
|
58
|
-
navigate(newUrl);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
if (newProps.persistentQuery) {
|
|
63
|
-
const params = parseQuery(window.location.search);
|
|
64
|
-
if (params.query) {
|
|
65
|
-
setQuery(params.query);
|
|
66
|
-
} else {
|
|
67
|
-
persistQuery(query);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
71
|
-
}, []);
|
|
72
|
-
|
|
73
|
-
const onEditQuery = (newQuery) => {
|
|
74
|
-
if (newQuery !== query && newProps.persistentQuery) {
|
|
75
|
-
persistQuery(newQuery);
|
|
76
|
-
}
|
|
77
|
-
setQuery(newQuery);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const onToggleExplorer = () => {
|
|
81
|
-
setComposerOpen(!queryComposerIsOpen);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const onToggleCodeExporter = () => setExporterOpen(!codeExporterIsOpen);
|
|
85
|
-
|
|
86
|
-
const ensureSubscriptionClient = () => {
|
|
87
|
-
if (subscriptionClient.current) {
|
|
88
|
-
subscriptionClient.current.close();
|
|
89
|
-
subscriptionClient.current = null;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const { endpoint } = newProps;
|
|
93
|
-
let socketUrl = endpoint.replace(/https?:\/\//, 'ws://');
|
|
94
|
-
if (endpoint.indexOf('https://') === 0) {
|
|
95
|
-
socketUrl = socketUrl.replace('ws://', 'wss://');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
subscriptionClient.current = new AbsintheSocketGraphiql.SubscriptionsClient(
|
|
99
|
-
localStorage.getItem('websocket') || `${socketUrl}/socket`,
|
|
100
|
-
{ reconnect: true, connectionParams: {} }
|
|
101
|
-
);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const httpFetcher = async (params) => {
|
|
105
|
-
const extraHeaders =
|
|
106
|
-
typeof newProps.extraHeaders === 'function' ? newProps.extraHeaders() : newProps.extraHeaders || {};
|
|
107
|
-
|
|
108
|
-
const res = await axios({
|
|
109
|
-
method: 'post',
|
|
110
|
-
url: newProps.endpoint,
|
|
111
|
-
data: params,
|
|
112
|
-
headers: Object.assign(
|
|
113
|
-
{
|
|
114
|
-
'Content-Type': 'application/json',
|
|
115
|
-
},
|
|
116
|
-
extraHeaders
|
|
117
|
-
),
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
return res.data;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const fetcher = (params) => {
|
|
124
|
-
if (params.query.indexOf('subscription') >= 0) {
|
|
125
|
-
ensureSubscriptionClient();
|
|
126
|
-
|
|
127
|
-
// disable subscription in test env
|
|
128
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
129
|
-
return graphQLFetcher(subscriptionClient.current, httpFetcher)(params);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return httpFetcher(params);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
useEffect(() => {
|
|
137
|
-
httpFetcher({
|
|
138
|
-
query: getIntrospectionQuery(),
|
|
139
|
-
}).then((result) => {
|
|
140
|
-
if (!graphiql.current) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
setSchema(buildClientSchema(result.data));
|
|
144
|
-
});
|
|
145
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
146
|
-
}, [graphiql.current]);
|
|
147
|
-
|
|
148
|
-
const { endpoint, title, enableCodeExporter, enableQueryComposer, enableHistory, extraCodeSnippets, ...rest } =
|
|
149
|
-
newProps;
|
|
150
|
-
const snippets = [...extraCodeSnippets, ...CodeExporterSnippets];
|
|
151
|
-
|
|
152
|
-
return (
|
|
153
|
-
<Container {...rest}>
|
|
154
|
-
<Script url="//cdn.jsdelivr.net/npm/@absinthe/socket-graphiql@0.2.1/compat/umd/index.js" />
|
|
155
|
-
{enableQueryComposer && (
|
|
156
|
-
<QueryComposer
|
|
157
|
-
schema={schema}
|
|
158
|
-
query={query}
|
|
159
|
-
onEdit={onEditQuery}
|
|
160
|
-
onRunOperation={(operationName) => graphiql.current.handleRunQuery(operationName)}
|
|
161
|
-
explorerIsOpen={queryComposerIsOpen}
|
|
162
|
-
onToggleExplorer={onToggleExplorer}
|
|
163
|
-
className="graphiql-explorer"
|
|
164
|
-
/>
|
|
165
|
-
)}
|
|
166
|
-
<GraphiQL ref={graphiql} fetcher={fetcher} schema={schema} query={query} onEditQuery={onEditQuery}>
|
|
167
|
-
<GraphiQL.Logo>{title}</GraphiQL.Logo>
|
|
168
|
-
<GraphiQL.Toolbar>
|
|
169
|
-
<PrettifyButton />
|
|
170
|
-
{enableHistory && <HistoryToggleButton />}
|
|
171
|
-
{enableQueryComposer && (
|
|
172
|
-
<GraphiQL.Button onClick={onToggleExplorer} label="Query Composer" title="Toggle Query Composer" />
|
|
173
|
-
)}
|
|
174
|
-
{enableCodeExporter && (
|
|
175
|
-
<GraphiQL.Button onClick={onToggleCodeExporter} label="Code Exporter" title="Toggle Code Exporter" />
|
|
176
|
-
)}
|
|
177
|
-
</GraphiQL.Toolbar>
|
|
178
|
-
</GraphiQL>
|
|
179
|
-
{enableCodeExporter && codeExporterIsOpen && (
|
|
180
|
-
<div className="graphiql-container graphiql-exporter-container">
|
|
181
|
-
<CodeExporter
|
|
182
|
-
hideCodeExporter={onToggleCodeExporter}
|
|
183
|
-
snippets={snippets}
|
|
184
|
-
serverUrl={endpoint}
|
|
185
|
-
query={query}
|
|
186
|
-
codeMirrorTheme="neo"
|
|
187
|
-
/>
|
|
188
|
-
</div>
|
|
189
|
-
)}
|
|
190
|
-
</Container>
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
GraphQLPlayground.propTypes = {
|
|
195
|
-
endpoint: PropTypes.string.isRequired,
|
|
196
|
-
defaultQuery: PropTypes.string,
|
|
197
|
-
title: PropTypes.string,
|
|
198
|
-
persistentQuery: PropTypes.bool,
|
|
199
|
-
enableQueryComposer: PropTypes.bool,
|
|
200
|
-
enableCodeExporter: PropTypes.bool,
|
|
201
|
-
enableHistory: PropTypes.bool,
|
|
202
|
-
extraCodeSnippets: PropTypes.array,
|
|
203
|
-
extraHeaders: PropTypes.any,
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
GraphQLPlayground.defaultProps = {
|
|
207
|
-
title: 'Query',
|
|
208
|
-
defaultQuery: '{}',
|
|
209
|
-
persistentQuery: false,
|
|
210
|
-
enableQueryComposer: true,
|
|
211
|
-
enableCodeExporter: false,
|
|
212
|
-
enableHistory: false,
|
|
213
|
-
extraCodeSnippets: [],
|
|
214
|
-
extraHeaders: {},
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
const Container = styled('div')`
|
|
218
|
-
display: flex;
|
|
219
|
-
flex-direction: row;
|
|
220
|
-
flex: 1;
|
|
221
|
-
overflow: hidden;
|
|
222
|
-
height: 100%;
|
|
223
|
-
position: relative;
|
|
224
|
-
|
|
225
|
-
@media (max-width: ${(props) => props.theme.breakpoints.values.md}px) {
|
|
226
|
-
margin-top: 30px;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
> .historyPaneWrap {
|
|
230
|
-
z-index: 8 !important;
|
|
231
|
-
width: 320px !important;
|
|
232
|
-
box-shadow: 5px 16px 10px 0 rgba(0, 0, 0, ${(props) => (props.theme.mode === 'light' ? 0.05 : 0.5)});
|
|
233
|
-
overflow-y: scroll;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
.doc-explorer-title-bar,
|
|
237
|
-
.history-title-bar {
|
|
238
|
-
height: 45px;
|
|
239
|
-
line-height: 45px;
|
|
240
|
-
padding: 0px 8px;
|
|
241
|
-
display: flex;
|
|
242
|
-
align-items: center;
|
|
243
|
-
justify-content: space-between;
|
|
244
|
-
}
|
|
245
|
-
.doc-explorer-title-bar {
|
|
246
|
-
padding: 0px 32px;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
.doc-explorer-title,
|
|
250
|
-
.history-title {
|
|
251
|
-
font-size: 14px;
|
|
252
|
-
font-weight: 900;
|
|
253
|
-
letter-spacing: 2px;
|
|
254
|
-
color: ${(props) => props.theme.typography.color.gray};
|
|
255
|
-
text-transform: uppercase;
|
|
256
|
-
text-align: left !important;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
.doc-explorer-contents {
|
|
260
|
-
min-height: 0;
|
|
261
|
-
}
|
|
262
|
-
.history-contents {
|
|
263
|
-
top: 45px !important;
|
|
264
|
-
background-color: ${(props) => props.theme.palette.background.default} !important;
|
|
265
|
-
border-top: 1px solid #e3e3e3 !important;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
.history-contents {
|
|
269
|
-
color: ${(props) => props.theme.typography.color.main};
|
|
270
|
-
p {
|
|
271
|
-
border-bottom: 1px solid #e3e3e3;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
.docExplorerHide {
|
|
276
|
-
color: ${(props) => props.theme.typography.color.main};
|
|
277
|
-
padding: 0;
|
|
278
|
-
cursor: pointer;
|
|
279
|
-
margin: -7px -8px -6px -12px;
|
|
280
|
-
opacity: 0.75;
|
|
281
|
-
font-size: 18px;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
.toolbar-button {
|
|
285
|
-
cursor: pointer;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
.graphiql-container {
|
|
289
|
-
.title {
|
|
290
|
-
color: ${(props) => props.theme.typography.color.main};
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
.topBar {
|
|
294
|
-
background-image: none;
|
|
295
|
-
height: 45px;
|
|
296
|
-
border-bottom-width: 0;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
.docExplorerShow {
|
|
300
|
-
background: ${(props) => props.theme.palette.background.default};
|
|
301
|
-
border: none;
|
|
302
|
-
font-size: 14px;
|
|
303
|
-
color: ${(props) => props.theme.typography.color.main};
|
|
304
|
-
text-transform: uppercase;
|
|
305
|
-
|
|
306
|
-
&::before {
|
|
307
|
-
border-color: ${(props) => props.theme.typography.color.gray};
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
.historyPaneWrap {
|
|
312
|
-
width: 320px !important;
|
|
313
|
-
background-color: ${(props) => props.theme.palette.background.default};
|
|
314
|
-
box-shadow: 5px 16px 10px 0 rgba(0, 0, 0, ${(props) => (props.theme.mode === 'light' ? 0.05 : 0.5)});
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
.search-box {
|
|
318
|
-
margin-bottom: 20px;
|
|
319
|
-
border-bottom: none;
|
|
320
|
-
|
|
321
|
-
input {
|
|
322
|
-
height: 30px;
|
|
323
|
-
border-radius: 15px;
|
|
324
|
-
border: solid 1px ${(props) => props.theme.typography.color.main};
|
|
325
|
-
padding: 6px 24px 8px 30px;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
.search-box-clear {
|
|
329
|
-
right: 10px;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
&::before {
|
|
333
|
-
left: 10px;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
.variable-editor-title {
|
|
338
|
-
background: ${(props) => props.theme.palette.background.default};
|
|
339
|
-
border: none;
|
|
340
|
-
height: 40px;
|
|
341
|
-
padding-left: 20px;
|
|
342
|
-
|
|
343
|
-
&::before {
|
|
344
|
-
border-left: 2px solid ${(props) => props.theme.typography.color.gray};
|
|
345
|
-
border-top: 2px solid ${(props) => props.theme.typography.color.gray};
|
|
346
|
-
content: '';
|
|
347
|
-
display: inline-block;
|
|
348
|
-
height: 9px;
|
|
349
|
-
margin: 0 5px 1px 0;
|
|
350
|
-
position: relative;
|
|
351
|
-
-webkit-transform: rotate(-135deg);
|
|
352
|
-
transform: rotate(-135deg);
|
|
353
|
-
width: 9px;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
.resultWrap {
|
|
358
|
-
border-left: none;
|
|
359
|
-
.CodeMirror-gutters {
|
|
360
|
-
opacity: 0.5;
|
|
361
|
-
}
|
|
362
|
-
.CodeMirror-gutter.CodeMirror-foldgutter {
|
|
363
|
-
box-shadow: 5px 16px 10px 0 rgba(0, 0, 0, ${(props) => (props.theme.mode === 'light' ? 0.05 : 0.5)});
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
.CodeMirror,
|
|
368
|
-
.CodeMirror-gutters,
|
|
369
|
-
.CodeMirror-linenumber,
|
|
370
|
-
.CodeMirror-foldgutter {
|
|
371
|
-
background: ${(props) => props.theme.palette.background.default};
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
.variable-editor {
|
|
375
|
-
.CodeMirror {
|
|
376
|
-
background: white;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
.CodeMirror-gutters {
|
|
381
|
-
border-right-width: 0;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
.graphiql-exporter-container {
|
|
386
|
-
width: auto;
|
|
387
|
-
.historyPaneWrap {
|
|
388
|
-
position: absolute !important;
|
|
389
|
-
height: 100%;
|
|
390
|
-
top: 0;
|
|
391
|
-
right: 0;
|
|
392
|
-
background-color: ${(props) => props.theme.palette.background.default};
|
|
393
|
-
box-shadow: -5px 16px 10px 0 rgba(0, 0, 0, ${(props) => (props.theme.mode === 'light' ? 0.05 : 0.5)});
|
|
394
|
-
z-index: 3;
|
|
395
|
-
|
|
396
|
-
.history-contents {
|
|
397
|
-
padding-top: 12px;
|
|
398
|
-
.toolbar-button {
|
|
399
|
-
margin-top: -24px !important;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
`;
|