@arcblock/graphql-playground 3.4.15 → 3.5.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/package.json +5 -2
- package/src/GraphqlPlayground.stories.jsx +0 -25
- package/src/index.jsx +0 -267
- package/src/util.js +0 -49
- package/vite.config.mjs +0 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/graphql-playground",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "A React Component to interact with GraphQL APIs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -43,6 +43,9 @@
|
|
|
43
43
|
"react": "^19.0.0",
|
|
44
44
|
"react-router-dom": "^6.22.3"
|
|
45
45
|
},
|
|
46
|
+
"files": [
|
|
47
|
+
"lib"
|
|
48
|
+
],
|
|
46
49
|
"publishConfig": {
|
|
47
50
|
"access": "public"
|
|
48
51
|
},
|
|
@@ -50,5 +53,5 @@
|
|
|
50
53
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
51
54
|
"jest": "^29.7.0"
|
|
52
55
|
},
|
|
53
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "1cfc816004525cf1b352ec2b64d459f4769f0237"
|
|
54
57
|
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import ThemeWrapper from './demo/theme-wrapper';
|
|
2
|
-
|
|
3
|
-
export { default as Basic } from './demo/basic';
|
|
4
|
-
export { default as WithHistory } from './demo/with-history';
|
|
5
|
-
export { default as WithQueryComposer } from './demo/with-query-composer';
|
|
6
|
-
export { default as WithCodeExporter } from './demo/with-code-exporter';
|
|
7
|
-
export { default as KitchenSink } from './demo/kitchen-sink';
|
|
8
|
-
|
|
9
|
-
export default {
|
|
10
|
-
title: 'Data Display/GraphQLPlayground',
|
|
11
|
-
parameters: {
|
|
12
|
-
docs: {
|
|
13
|
-
description: {
|
|
14
|
-
component: 'A GraphQL Playground component built on top of `graphql/graphiql`',
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
decorators: [
|
|
19
|
-
(Story) => (
|
|
20
|
-
<ThemeWrapper>
|
|
21
|
-
<Story />
|
|
22
|
-
</ThemeWrapper>
|
|
23
|
-
),
|
|
24
|
-
],
|
|
25
|
-
};
|
package/src/index.jsx
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import { mergeProps } from '@arcblock/ux/lib/Util';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { styled, useTheme } from '@arcblock/ux/lib/Theme';
|
|
4
|
-
import { GraphiQL } from 'graphiql';
|
|
5
|
-
// eslint-disable-next-line import/no-unresolved
|
|
6
|
-
import { explorerPlugin } from '@graphiql/plugin-explorer';
|
|
7
|
-
import { createGraphiQLFetcher } from '@graphiql/toolkit';
|
|
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
|
-
export default function GraphQLPlayground({ ...rawProps }) {
|
|
15
|
-
const theme = useTheme();
|
|
16
|
-
const props = Object.assign(
|
|
17
|
-
{
|
|
18
|
-
title: 'Query',
|
|
19
|
-
defaultQuery: '{}',
|
|
20
|
-
persistentQuery: false,
|
|
21
|
-
enableQueryComposer: true,
|
|
22
|
-
enableCodeExporter: false,
|
|
23
|
-
enableHistory: false,
|
|
24
|
-
extraCodeSnippets: [],
|
|
25
|
-
extraHeaders: {},
|
|
26
|
-
},
|
|
27
|
-
rawProps
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const newProps = mergeProps(props, GraphQLPlayground, [
|
|
31
|
-
'style',
|
|
32
|
-
'persistentQuery',
|
|
33
|
-
'enableQueryComposer',
|
|
34
|
-
'enableCodeExporter',
|
|
35
|
-
'enableHistory',
|
|
36
|
-
]);
|
|
37
|
-
const extraHeaders =
|
|
38
|
-
typeof newProps.extraHeaders === 'function' ? newProps.extraHeaders() : newProps.extraHeaders || {};
|
|
39
|
-
|
|
40
|
-
const fetcher = createGraphiQLFetcher({
|
|
41
|
-
url: newProps.endpoint,
|
|
42
|
-
headers: extraHeaders,
|
|
43
|
-
});
|
|
44
|
-
const explorer = explorerPlugin();
|
|
45
|
-
// FIXME: @zhanghan HISTORY_PLUGIN 会导致 webapp 报错,之后再修复
|
|
46
|
-
// import { HISTORY_PLUGIN } from 'graphiql';
|
|
47
|
-
const plugins = [explorer];
|
|
48
|
-
const {
|
|
49
|
-
endpoint,
|
|
50
|
-
title,
|
|
51
|
-
enableCodeExporter,
|
|
52
|
-
enableQueryComposer,
|
|
53
|
-
enableHistory,
|
|
54
|
-
extraCodeSnippets,
|
|
55
|
-
defaultQuery,
|
|
56
|
-
persistentQuery,
|
|
57
|
-
...rest
|
|
58
|
-
} = newProps;
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<Container {...rest}>
|
|
62
|
-
<GraphiQL fetcher={fetcher} plugins={plugins} defaultQuery={defaultQuery} forcedTheme={theme.palette.mode} />
|
|
63
|
-
</Container>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
GraphQLPlayground.propTypes = {
|
|
68
|
-
endpoint: PropTypes.string.isRequired,
|
|
69
|
-
defaultQuery: PropTypes.string,
|
|
70
|
-
title: PropTypes.string,
|
|
71
|
-
persistentQuery: PropTypes.bool,
|
|
72
|
-
enableQueryComposer: PropTypes.bool,
|
|
73
|
-
enableCodeExporter: PropTypes.bool,
|
|
74
|
-
enableHistory: PropTypes.bool,
|
|
75
|
-
extraCodeSnippets: PropTypes.array,
|
|
76
|
-
extraHeaders: PropTypes.any,
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const Container = styled('div')`
|
|
80
|
-
display: flex;
|
|
81
|
-
flex-direction: row;
|
|
82
|
-
flex: 1;
|
|
83
|
-
overflow: hidden;
|
|
84
|
-
height: 100%;
|
|
85
|
-
position: relative;
|
|
86
|
-
|
|
87
|
-
@media (max-width: ${(props) => props.theme.breakpoints.values.md}px) {
|
|
88
|
-
margin-top: 30px;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
> .historyPaneWrap {
|
|
92
|
-
z-index: 8 !important;
|
|
93
|
-
width: 320px !important;
|
|
94
|
-
box-shadow: 5px 16px 10px 0 rgba(0, 0, 0, ${(props) => (props.theme.mode === 'light' ? 0.05 : 0.5)});
|
|
95
|
-
overflow-y: scroll;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
.doc-explorer-title-bar,
|
|
99
|
-
.history-title-bar {
|
|
100
|
-
height: 45px;
|
|
101
|
-
line-height: 45px;
|
|
102
|
-
padding: 0px 8px;
|
|
103
|
-
display: flex;
|
|
104
|
-
align-items: center;
|
|
105
|
-
justify-content: space-between;
|
|
106
|
-
}
|
|
107
|
-
.doc-explorer-title-bar {
|
|
108
|
-
padding: 0px 32px;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
.doc-explorer-title,
|
|
112
|
-
.history-title {
|
|
113
|
-
font-size: 14px;
|
|
114
|
-
font-weight: 900;
|
|
115
|
-
letter-spacing: 2px;
|
|
116
|
-
color: ${({ theme }) => theme.palette.text.secondary};
|
|
117
|
-
text-transform: uppercase;
|
|
118
|
-
text-align: left !important;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
.doc-explorer-contents {
|
|
122
|
-
min-height: 0;
|
|
123
|
-
}
|
|
124
|
-
.history-contents {
|
|
125
|
-
top: 45px !important;
|
|
126
|
-
background-color: ${({ theme }) => theme.palette.background.default} !important;
|
|
127
|
-
border-top: 1px solid !important;
|
|
128
|
-
border-color: ${({ theme }) => theme.palette.divider} !important;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
.history-contents {
|
|
132
|
-
color: ${({ theme }) => theme.palette.text.primary};
|
|
133
|
-
p {
|
|
134
|
-
border-bottom: 1px solid ${({ theme }) => theme.palette.divider};
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
.docExplorerHide {
|
|
139
|
-
color: ${({ theme }) => theme.palette.text.primary};
|
|
140
|
-
padding: 0;
|
|
141
|
-
cursor: pointer;
|
|
142
|
-
margin: -7px -8px -6px -12px;
|
|
143
|
-
opacity: 0.75;
|
|
144
|
-
font-size: 18px;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
.toolbar-button {
|
|
148
|
-
cursor: pointer;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
.graphiql-container {
|
|
152
|
-
.title {
|
|
153
|
-
color: ${({ theme }) => theme.palette.text.primary};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
.topBar {
|
|
157
|
-
background-image: none;
|
|
158
|
-
height: 45px;
|
|
159
|
-
border-bottom-width: 0;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
.docExplorerShow {
|
|
163
|
-
background: ${({ theme }) => theme.palette.background.default};
|
|
164
|
-
border: none;
|
|
165
|
-
font-size: 14px;
|
|
166
|
-
color: ${({ theme }) => theme.palette.text.primary};
|
|
167
|
-
text-transform: uppercase;
|
|
168
|
-
|
|
169
|
-
&::before {
|
|
170
|
-
border-color: ${({ theme }) => theme.palette.divider};
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
.historyPaneWrap {
|
|
175
|
-
width: 320px !important;
|
|
176
|
-
background-color: ${({ theme }) => theme.palette.background.default};
|
|
177
|
-
box-shadow: 5px 16px 10px 0 rgba(0, 0, 0, ${(props) => (props.theme.mode === 'light' ? 0.05 : 0.5)});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
.search-box {
|
|
181
|
-
margin-bottom: 20px;
|
|
182
|
-
border-bottom: none;
|
|
183
|
-
|
|
184
|
-
input {
|
|
185
|
-
height: 30px;
|
|
186
|
-
border-radius: 15px;
|
|
187
|
-
border: solid 1px ${({ theme }) => theme.palette.divider};
|
|
188
|
-
padding: 6px 24px 8px 30px;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
.search-box-clear {
|
|
192
|
-
right: 10px;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
&::before {
|
|
196
|
-
left: 10px;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
.variable-editor-title {
|
|
201
|
-
background: ${({ theme }) => theme.palette.background.default};
|
|
202
|
-
border: none;
|
|
203
|
-
height: 40px;
|
|
204
|
-
padding-left: 20px;
|
|
205
|
-
|
|
206
|
-
&::before {
|
|
207
|
-
border-left: 2px solid ${({ theme }) => theme.palette.divider};
|
|
208
|
-
border-top: 2px solid ${({ theme }) => theme.palette.divider};
|
|
209
|
-
content: '';
|
|
210
|
-
display: inline-block;
|
|
211
|
-
height: 9px;
|
|
212
|
-
margin: 0 5px 1px 0;
|
|
213
|
-
position: relative;
|
|
214
|
-
-webkit-transform: rotate(-135deg);
|
|
215
|
-
transform: rotate(-135deg);
|
|
216
|
-
width: 9px;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
.resultWrap {
|
|
221
|
-
border-left: none;
|
|
222
|
-
.CodeMirror-gutters {
|
|
223
|
-
opacity: 0.5;
|
|
224
|
-
}
|
|
225
|
-
.CodeMirror-gutter.CodeMirror-foldgutter {
|
|
226
|
-
box-shadow: 5px 16px 10px 0 rgba(0, 0, 0, ${(props) => (props.theme.mode === 'light' ? 0.05 : 0.5)});
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
.CodeMirror,
|
|
231
|
-
.CodeMirror-gutters,
|
|
232
|
-
.CodeMirror-linenumber,
|
|
233
|
-
.CodeMirror-foldgutter {
|
|
234
|
-
background: ${({ theme }) => theme.palette.background.default};
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
.variable-editor {
|
|
238
|
-
.CodeMirror {
|
|
239
|
-
background: white;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
.CodeMirror-gutters {
|
|
244
|
-
border-right-width: 0;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
.graphiql-exporter-container {
|
|
249
|
-
width: auto;
|
|
250
|
-
.historyPaneWrap {
|
|
251
|
-
position: absolute !important;
|
|
252
|
-
height: 100%;
|
|
253
|
-
top: 0;
|
|
254
|
-
right: 0;
|
|
255
|
-
background-color: ${({ theme }) => theme.palette.background.default};
|
|
256
|
-
box-shadow: -5px 16px 10px 0 rgba(0, 0, 0, ${({ theme }) => (theme.mode === 'light' ? 0.05 : 0.5)});
|
|
257
|
-
z-index: 3;
|
|
258
|
-
|
|
259
|
-
.history-contents {
|
|
260
|
-
padding-top: 12px;
|
|
261
|
-
.toolbar-button {
|
|
262
|
-
margin-top: -24px !important;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
`;
|
package/src/util.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { parse } from 'graphql';
|
|
2
|
-
|
|
3
|
-
const hasSubscriptionOperation = (graphQlParams) => {
|
|
4
|
-
const queryDoc = parse(graphQlParams.query);
|
|
5
|
-
|
|
6
|
-
for (const definition of queryDoc.definitions) {
|
|
7
|
-
if (definition.kind === 'OperationDefinition') {
|
|
8
|
-
if (definition.operation === 'subscription') {
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return false;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
18
|
-
export const graphQLFetcher = (subscriptionsClient, fallbackFetcher) => {
|
|
19
|
-
let activeSubscriptionId = null;
|
|
20
|
-
|
|
21
|
-
return (params) => {
|
|
22
|
-
if (subscriptionsClient && activeSubscriptionId !== null) {
|
|
23
|
-
subscriptionsClient.unsubscribe(activeSubscriptionId);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (subscriptionsClient && hasSubscriptionOperation(params)) {
|
|
27
|
-
return {
|
|
28
|
-
subscribe(observer) {
|
|
29
|
-
observer.next('Your subscription data will appear here after server publication!');
|
|
30
|
-
|
|
31
|
-
activeSubscriptionId = subscriptionsClient.subscribe(
|
|
32
|
-
{
|
|
33
|
-
query: params.query,
|
|
34
|
-
variables: params.variables,
|
|
35
|
-
},
|
|
36
|
-
(error, result) => {
|
|
37
|
-
if (error) {
|
|
38
|
-
observer.error(error);
|
|
39
|
-
} else {
|
|
40
|
-
observer.next(result);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
);
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return fallbackFetcher(params);
|
|
48
|
-
};
|
|
49
|
-
};
|
package/vite.config.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
});
|