@arcblock/graphql-playground 3.0.9 → 3.0.11

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.
Files changed (3) hide show
  1. package/lib/index.js +37 -28
  2. package/package.json +6 -5
  3. package/src/index.jsx +19 -28
package/lib/index.js CHANGED
@@ -1,48 +1,57 @@
1
- import { jsx as i } from "react/jsx-runtime";
2
- import o from "prop-types";
1
+ import { jsx as t } from "react/jsx-runtime";
2
+ import r from "prop-types";
3
3
  import { styled as x } from "@arcblock/ux/lib/Theme";
4
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";
5
+ import { explorerPlugin as g } from "@graphiql/plugin-explorer";
6
+ import { createGraphiQLFetcher as m } from "@graphiql/toolkit";
8
7
  import "graphiql/style.css";
9
8
  import "@graphiql/plugin-explorer/style.css";
10
9
  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, [
10
+ function p({ ...e }) {
11
+ const a = Object.assign(
12
+ {
13
+ title: "Query",
14
+ defaultQuery: "{}",
15
+ persistentQuery: !1,
16
+ enableQueryComposer: !0,
17
+ enableCodeExporter: !1,
18
+ enableHistory: !1,
19
+ extraCodeSnippets: [],
20
+ extraHeaders: {}
21
+ },
22
+ e
23
+ ), o = b(a, p, [
15
24
  "style",
16
25
  "persistentQuery",
17
26
  "enableQueryComposer",
18
27
  "enableCodeExporter",
19
28
  "enableHistory"
20
- ]), n = g({
21
- url: p.endpoint
22
- }), l = [m()], {
29
+ ]), i = typeof o.extraHeaders == "function" ? o.extraHeaders() : o.extraHeaders || {}, n = m({
30
+ url: o.endpoint,
31
+ headers: i
32
+ }), l = [g()], {
23
33
  endpoint: y,
24
34
  title: f,
25
35
  enableCodeExporter: C,
26
36
  enableQueryComposer: w,
27
37
  enableHistory: $,
28
- extraCodeSnippets: Q,
38
+ extraCodeSnippets: k,
29
39
  defaultQuery: d,
30
- extraHeaders: k,
31
- persistentQuery: H,
40
+ persistentQuery: Q,
32
41
  ...s
33
- } = p;
34
- return /* @__PURE__ */ i(c, { ...s, children: /* @__PURE__ */ i(h, { fetcher: n, plugins: l, defaultQuery: d }) });
42
+ } = o;
43
+ return /* @__PURE__ */ t(c, { ...s, children: /* @__PURE__ */ t(h, { fetcher: n, plugins: l, defaultQuery: d }) });
35
44
  }
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
45
+ p.propTypes = {
46
+ endpoint: r.string.isRequired,
47
+ defaultQuery: r.string,
48
+ title: r.string,
49
+ persistentQuery: r.bool,
50
+ enableQueryComposer: r.bool,
51
+ enableCodeExporter: r.bool,
52
+ enableHistory: r.bool,
53
+ extraCodeSnippets: r.array,
54
+ extraHeaders: r.any
46
55
  };
47
56
  const c = x("div")`
48
57
  display: flex;
@@ -233,5 +242,5 @@ const c = x("div")`
233
242
  }
234
243
  `;
235
244
  export {
236
- a as default
245
+ p as default
237
246
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/graphql-playground",
3
- "version": "3.0.9",
3
+ "version": "3.0.11",
4
4
  "description": "A React Component to interact with GraphQL APIs",
5
5
  "keywords": [
6
6
  "react",
@@ -30,13 +30,14 @@
30
30
  "url": "https://github.com/ArcBlock/ux/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@graphiql/plugin-explorer": "^4.0.6",
33
+ "@graphiql/plugin-explorer": "^5.0.0",
34
+ "@graphiql/toolkit": "^0.11.3",
34
35
  "axios": "^1.10.0",
35
- "graphiql": "^4.1.2",
36
+ "graphiql": "^5.0.3",
36
37
  "graphql": "^16.11.0"
37
38
  },
38
39
  "peerDependencies": {
39
- "@arcblock/ux": "^3.0.8",
40
+ "@arcblock/ux": "^3.0.10",
40
41
  "@emotion/react": "^11.14.0",
41
42
  "@emotion/styled": "^11.14.0",
42
43
  "react": "^19.0.0",
@@ -49,5 +50,5 @@
49
50
  "eslint-plugin-react-hooks": "^4.6.2",
50
51
  "jest": "^29.7.0"
51
52
  },
52
- "gitHead": "e2283285cb6e99f09146cde5e1af002e55091619"
53
+ "gitHead": "3619d5d23622fb8074ace5f6c685bcc25c14c056"
53
54
  }
package/src/index.jsx CHANGED
@@ -4,7 +4,6 @@ import { GraphiQL } from 'graphiql';
4
4
  // eslint-disable-next-line import/no-unresolved
5
5
  import { explorerPlugin } from '@graphiql/plugin-explorer';
6
6
  import { createGraphiQLFetcher } from '@graphiql/toolkit';
7
- import isUndefined from 'lodash/isUndefined';
8
7
 
9
8
  // eslint-disable-next-line import/no-unresolved
10
9
  import 'graphiql/style.css';
@@ -14,31 +13,20 @@ import '@graphiql/plugin-explorer/style.css';
14
13
  import { mergeProps } from '@arcblock/ux/lib/Util';
15
14
 
16
15
  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
- }
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
+
42
30
  const newProps = mergeProps(props, GraphQLPlayground, [
43
31
  'style',
44
32
  'persistentQuery',
@@ -46,13 +34,17 @@ export default function GraphQLPlayground({ ...rawProps }) {
46
34
  'enableCodeExporter',
47
35
  'enableHistory',
48
36
  ]);
37
+ const extraHeaders =
38
+ typeof newProps.extraHeaders === 'function' ? newProps.extraHeaders() : newProps.extraHeaders || {};
49
39
 
50
40
  const fetcher = createGraphiQLFetcher({
51
41
  url: newProps.endpoint,
42
+ headers: extraHeaders,
52
43
  });
53
44
  const explorer = explorerPlugin();
45
+ // FIXME: @zhanghan HISTORY_PLUGIN 会导致 webapp 报错,之后再修复
46
+ // import { HISTORY_PLUGIN } from 'graphiql';
54
47
  const plugins = [explorer];
55
-
56
48
  const {
57
49
  endpoint,
58
50
  title,
@@ -61,7 +53,6 @@ export default function GraphQLPlayground({ ...rawProps }) {
61
53
  enableHistory,
62
54
  extraCodeSnippets,
63
55
  defaultQuery,
64
- extraHeaders,
65
56
  persistentQuery,
66
57
  ...rest
67
58
  } = newProps;