@arcblock/graphql-playground

中文文档
3.5.4发布于 2026/06/13Apache-2.0CommonJS近 30 天下载 1746

A React Component to interact with GraphQL APIs

原始使用文档

@arcblock/graphql-playground

A React Component to interact with GraphQL APIs

Usage

yarn add @arcblock/graphql-playground

Then:

import React from 'react';
import GraphQLPlayground from '@arcblock/graphql-playground';

function App() {
  return (
    <GraphQLPlayground
      defaultQuery={defaultQuery}
      endpoint={endpoint}
      title="My Graphql Playground"
      persistentQuery={false}
      enableHistory
      enableQueryComposer
      enableCodeExporter
    />
  );
}

How to use GraphQLPlayground comonent in SSR env such as gatsby?

Because graphiql and graphiql-code-exporter uses browser globals such as window, we need to mock them both during building time for gatsby.

First we need to create an mock for graphqil, src/mocks/graphiql:

function graphiql() {
  return null;
}

graphiql.Logo = () => null;
graphiql.Toolbar = () => null;
graphiql.QueryEditor = () => null;
graphiql.VariableEditor = () => null;
graphiql.ResultViewer = () => null;
graphiql.Button = () => null;
graphiql.ToolbarButton = () => null;
graphiql.Group = () => null;
graphiql.Menu = () => null;
graphiql.MenuItem = () => null;
graphiql.Select = () => null;
graphiql.SelectOption = () => null;
graphiql.Footer = () => null;

module.exports = graphiql;

Then, in gatsby-node.js, use the mocks:

const path = require('node:path');

exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
  if (stage === 'build-html') {
    actions.setWebpackConfig({
      resolve: {
        alias: {
          graphiql: path.resolve(__dirname, './src/mocks/graphiql.js'),
        },
      },
      module: {
        rules: [
          {
            test: /node_modules\/codemirror\//,
            use: loaders.null(),
          },
        ],
      },
    });
  }
};

版本与发布记录

@arcblock/graphql-playground 共发布 968 个版本,首次发布于 2020/04/03;过去 12 个月发布了 49 个版本。

版本发布日期距今
3.5.4latest2026/06/134 个月前
3.5.32026/04/246 个月前
3.5.22026/02/108 个月前
3.5.12026/02/098 个月前
3.5.02026/02/039 个月前
3.4.152026/02/039 个月前

关于 @arcblock/graphql-playground 的常见问题

@arcblock/graphql-playground 是什么?

A React Component to interact with GraphQL APIs

如何安装 @arcblock/graphql-playground?

在项目目录运行 npm install @arcblock/graphql-playground,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@arcblock/ux(^3.1.0)、@emotion/react(^11.14.0)、@emotion/styled(^11.14.0)、react(^19.0.0)、react-router-dom(^6.30.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@arcblock/graphql-playground 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/arcblock__graphql-playground 是否存在。

@arcblock/graphql-playground 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@arcblock/graphql-playground 可以商用吗?

@arcblock/graphql-playground 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@arcblock/graphql-playground 的下载量有多少?

根据 npm 官方下载统计,@arcblock/graphql-playground 在 2026/10/07 – 2026/11/05 这 30 天内被下载 1,746 次,日均约 58 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@arcblock/graphql-playground 还在维护吗?

最新版本 3.5.4 发布于 2026/06/13(4 个月前);至今共发布 968 个版本,其中过去 12 个月发布了 49 个;首次发布于 2020/04/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。