@arcblock/graphql-playground 2.5.58 → 2.5.60
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/index.js +20 -62
- package/lib/util.js +2 -10
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -4,61 +4,38 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = GraphQLPlayground;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _Theme = require("@arcblock/ux/lib/Theme");
|
|
13
|
-
|
|
14
10
|
var _axios = _interopRequireDefault(require("axios"));
|
|
15
|
-
|
|
16
11
|
var _reactLoadScript = _interopRequireDefault(require("react-load-script"));
|
|
17
|
-
|
|
18
12
|
var _graphiql = _interopRequireDefault(require("graphiql"));
|
|
19
|
-
|
|
20
13
|
var _graphiqlExplorer = _interopRequireDefault(require("graphiql-explorer"));
|
|
21
|
-
|
|
22
14
|
var _graphiqlCodeExporter = _interopRequireDefault(require("graphiql-code-exporter"));
|
|
23
|
-
|
|
24
15
|
var _snippets = _interopRequireDefault(require("graphiql-code-exporter/lib/snippets"));
|
|
25
|
-
|
|
26
16
|
var _graphql = require("graphql");
|
|
27
|
-
|
|
28
17
|
var _react2 = require("@graphiql/react");
|
|
29
|
-
|
|
30
18
|
var _reactRouterDom = require("react-router-dom");
|
|
31
|
-
|
|
32
19
|
require("graphiql/graphiql.css");
|
|
33
|
-
|
|
34
20
|
require("graphiql-code-exporter/CodeExporter.css");
|
|
35
|
-
|
|
36
21
|
require("codemirror/theme/neo.css");
|
|
37
|
-
|
|
38
22
|
var _Util = require("@arcblock/ux/lib/Util");
|
|
39
|
-
|
|
40
23
|
var _util = require("./util");
|
|
41
|
-
|
|
42
24
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
43
|
-
|
|
44
25
|
var _templateObject;
|
|
45
|
-
|
|
46
26
|
const _excluded = ["endpoint", "title", "enableCodeExporter", "enableQueryComposer", "enableHistory", "extraCodeSnippets"];
|
|
47
|
-
|
|
27
|
+
/* eslint-disable indent */
|
|
28
|
+
/* eslint-disable no-nested-ternary */
|
|
29
|
+
/* eslint-disable no-undef */
|
|
48
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
49
|
-
|
|
50
31
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
51
|
-
|
|
52
32
|
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
|
-
|
|
54
33
|
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
|
-
|
|
56
|
-
function
|
|
57
|
-
|
|
34
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
35
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
36
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
58
37
|
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; }
|
|
59
|
-
|
|
60
38
|
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; }
|
|
61
|
-
|
|
62
39
|
function HistoryToggleButton() {
|
|
63
40
|
const {
|
|
64
41
|
toggle
|
|
@@ -69,7 +46,6 @@ function HistoryToggleButton() {
|
|
|
69
46
|
title: "Show History"
|
|
70
47
|
});
|
|
71
48
|
}
|
|
72
|
-
|
|
73
49
|
function PrettifyButton() {
|
|
74
50
|
const prettify = (0, _react2.usePrettifyEditors)();
|
|
75
51
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_graphiql.default.Button, {
|
|
@@ -78,7 +54,6 @@ function PrettifyButton() {
|
|
|
78
54
|
title: "Prettify Query (Shift-Ctrl-P)"
|
|
79
55
|
});
|
|
80
56
|
}
|
|
81
|
-
|
|
82
57
|
function GraphQLPlayground(props) {
|
|
83
58
|
const newProps = (0, _Util.mergeProps)(props, GraphQLPlayground, ['style', 'persistentQuery', 'enableQueryComposer', 'enableCodeExporter', 'enableHistory']);
|
|
84
59
|
const location = (0, _reactRouterDom.useLocation)();
|
|
@@ -89,7 +64,6 @@ function GraphQLPlayground(props) {
|
|
|
89
64
|
const [query, setQuery] = (0, _react.useState)(newProps.defaultQuery || '{}');
|
|
90
65
|
const [queryComposerIsOpen, setComposerOpen] = (0, _react.useState)(newProps.enableQueryComposer);
|
|
91
66
|
const [codeExporterIsOpen, setExporterOpen] = (0, _react.useState)(false);
|
|
92
|
-
|
|
93
67
|
const persistQuery = newQuery => {
|
|
94
68
|
const {
|
|
95
69
|
pathname,
|
|
@@ -100,55 +74,44 @@ function GraphQLPlayground(props) {
|
|
|
100
74
|
const newUrl = "".concat(pathname, "?").concat((0, _Util.stringifyQuery)(params));
|
|
101
75
|
navigate(newUrl);
|
|
102
76
|
};
|
|
103
|
-
|
|
104
77
|
(0, _react.useEffect)(() => {
|
|
105
78
|
if (newProps.persistentQuery) {
|
|
106
79
|
const params = (0, _Util.parseQuery)(window.location.search);
|
|
107
|
-
|
|
108
80
|
if (params.query) {
|
|
109
81
|
setQuery(params.query);
|
|
110
82
|
} else {
|
|
111
83
|
persistQuery(query);
|
|
112
84
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
85
|
+
}
|
|
86
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
115
87
|
}, []);
|
|
116
|
-
|
|
117
88
|
const onEditQuery = newQuery => {
|
|
118
89
|
if (newQuery !== query && newProps.persistentQuery) {
|
|
119
90
|
persistQuery(newQuery);
|
|
120
91
|
}
|
|
121
|
-
|
|
122
92
|
setQuery(newQuery);
|
|
123
93
|
};
|
|
124
|
-
|
|
125
94
|
const onToggleExplorer = () => {
|
|
126
95
|
setComposerOpen(!queryComposerIsOpen);
|
|
127
96
|
};
|
|
128
|
-
|
|
129
97
|
const onToggleCodeExporter = () => setExporterOpen(!codeExporterIsOpen);
|
|
130
|
-
|
|
131
98
|
const ensureSubscriptionClient = () => {
|
|
132
99
|
if (subscriptionClient.current) {
|
|
133
100
|
subscriptionClient.current.close();
|
|
134
101
|
subscriptionClient.current = null;
|
|
135
102
|
}
|
|
136
|
-
|
|
137
103
|
const {
|
|
138
104
|
endpoint
|
|
139
105
|
} = newProps;
|
|
140
106
|
let socketUrl = endpoint.replace(/https?:\/\//, 'ws://');
|
|
141
|
-
|
|
142
107
|
if (endpoint.indexOf('https://') === 0) {
|
|
143
108
|
socketUrl = socketUrl.replace('ws://', 'wss://');
|
|
144
109
|
}
|
|
145
|
-
|
|
146
110
|
subscriptionClient.current = new AbsintheSocketGraphiql.SubscriptionsClient(localStorage.getItem('websocket') || "".concat(socketUrl, "/socket"), {
|
|
147
111
|
reconnect: true,
|
|
148
112
|
connectionParams: {}
|
|
149
113
|
});
|
|
150
114
|
};
|
|
151
|
-
|
|
152
115
|
const httpFetcher = async params => {
|
|
153
116
|
const extraHeaders = typeof newProps.extraHeaders === 'function' ? newProps.extraHeaders() : newProps.extraHeaders || {};
|
|
154
117
|
const res = await (0, _axios.default)({
|
|
@@ -161,19 +124,17 @@ function GraphQLPlayground(props) {
|
|
|
161
124
|
});
|
|
162
125
|
return res.data;
|
|
163
126
|
};
|
|
164
|
-
|
|
165
127
|
const fetcher = params => {
|
|
166
128
|
if (params.query.indexOf('subscription') >= 0) {
|
|
167
|
-
ensureSubscriptionClient();
|
|
129
|
+
ensureSubscriptionClient();
|
|
168
130
|
|
|
131
|
+
// disable subscription in test env
|
|
169
132
|
if (process.env.NODE_ENV !== 'test') {
|
|
170
133
|
return (0, _util.graphQLFetcher)(subscriptionClient.current, httpFetcher)(params);
|
|
171
134
|
}
|
|
172
135
|
}
|
|
173
|
-
|
|
174
136
|
return httpFetcher(params);
|
|
175
137
|
};
|
|
176
|
-
|
|
177
138
|
(0, _react.useEffect)(() => {
|
|
178
139
|
httpFetcher({
|
|
179
140
|
query: (0, _graphql.getIntrospectionQuery)()
|
|
@@ -181,21 +142,19 @@ function GraphQLPlayground(props) {
|
|
|
181
142
|
if (!graphiql.current) {
|
|
182
143
|
return;
|
|
183
144
|
}
|
|
184
|
-
|
|
185
145
|
setSchema((0, _graphql.buildClientSchema)(result.data));
|
|
186
|
-
});
|
|
146
|
+
});
|
|
147
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
187
148
|
}, [graphiql.current]);
|
|
188
|
-
|
|
189
149
|
const {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
150
|
+
endpoint,
|
|
151
|
+
title,
|
|
152
|
+
enableCodeExporter,
|
|
153
|
+
enableQueryComposer,
|
|
154
|
+
enableHistory,
|
|
155
|
+
extraCodeSnippets
|
|
156
|
+
} = newProps,
|
|
157
|
+
rest = _objectWithoutProperties(newProps, _excluded);
|
|
199
158
|
const snippets = [...extraCodeSnippets, ..._snippets.default];
|
|
200
159
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Container, _objectSpread(_objectSpread({}, rest), {}, {
|
|
201
160
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactLoadScript.default, {
|
|
@@ -239,7 +198,6 @@ function GraphQLPlayground(props) {
|
|
|
239
198
|
})]
|
|
240
199
|
}));
|
|
241
200
|
}
|
|
242
|
-
|
|
243
201
|
GraphQLPlayground.propTypes = {
|
|
244
202
|
endpoint: _propTypes.default.string.isRequired,
|
|
245
203
|
defaultQuery: _propTypes.default.string,
|
package/lib/util.js
CHANGED
|
@@ -4,12 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.graphQLFetcher = void 0;
|
|
7
|
-
|
|
8
7
|
var _graphql = require("graphql");
|
|
9
|
-
|
|
10
8
|
const hasSubscriptionOperation = graphQlParams => {
|
|
11
9
|
const queryDoc = (0, _graphql.parse)(graphQlParams.query);
|
|
12
|
-
|
|
13
10
|
for (const definition of queryDoc.definitions) {
|
|
14
11
|
if (definition.kind === 'OperationDefinition') {
|
|
15
12
|
if (definition.operation === 'subscription') {
|
|
@@ -17,18 +14,16 @@ const hasSubscriptionOperation = graphQlParams => {
|
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
return false;
|
|
22
|
-
};
|
|
23
|
-
|
|
18
|
+
};
|
|
24
19
|
|
|
20
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
25
21
|
const graphQLFetcher = (subscriptionsClient, fallbackFetcher) => {
|
|
26
22
|
let activeSubscriptionId = null;
|
|
27
23
|
return params => {
|
|
28
24
|
if (subscriptionsClient && activeSubscriptionId !== null) {
|
|
29
25
|
subscriptionsClient.unsubscribe(activeSubscriptionId);
|
|
30
26
|
}
|
|
31
|
-
|
|
32
27
|
if (subscriptionsClient && hasSubscriptionOperation(params)) {
|
|
33
28
|
return {
|
|
34
29
|
subscribe(observer) {
|
|
@@ -44,12 +39,9 @@ const graphQLFetcher = (subscriptionsClient, fallbackFetcher) => {
|
|
|
44
39
|
}
|
|
45
40
|
});
|
|
46
41
|
}
|
|
47
|
-
|
|
48
42
|
};
|
|
49
43
|
}
|
|
50
|
-
|
|
51
44
|
return fallbackFetcher(params);
|
|
52
45
|
};
|
|
53
46
|
};
|
|
54
|
-
|
|
55
47
|
exports.graphQLFetcher = graphQLFetcher;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/graphql-playground",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.60",
|
|
4
4
|
"description": "A React Component to interact with GraphQL APIs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"url": "https://github.com/ArcBlock/ux/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@arcblock/ux": "^2.5.
|
|
33
|
+
"@arcblock/ux": "^2.5.60",
|
|
34
34
|
"@emotion/react": "^11.10.4",
|
|
35
35
|
"@emotion/styled": "^11.10.4",
|
|
36
36
|
"axios": "^0.27.2",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
57
57
|
"jest": "^28.1.3"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "50a0f90ecfb1d239e04cdfebc16e30d3947db4a2"
|
|
60
60
|
}
|