@acala-network/acala-transfers-subql 中文文档教程

发布于 3年前 浏览 18 更新于 3年前

SubQuery - Starter Package

Starter Package 是一个示例,您可以将其用作开发 SubQuery 项目的起点。 SubQuery 包定义了 SubQuery 将从 Substrate 区块链索引哪些数据,以及它将如何存储这些数据。

Preparation

Environment

  • Typescript 是编译项目和定义类型所必需的。

  • SubQuery CLI 和生成的项目都具有依赖关系,并且需要 Node

Install the SubQuery CLI

使用 NPM 在您的终端上全局安装 SubQuery CLI:

npm install -g @subql/cli

运行帮助以查看 CLI 提供的可用命令和用法

subql help

Initialize the starter package

在您要创建 SubQuery 项目的目录中,只需将 project-name 替换为您的项目name 并运行命令:

subql init --starter project-name

然后你应该看到目录中已经创建了一个包含你的项目名称的文件夹,你可以将其用作项目的起点。 这些文件应该与 目录结构 中的相同。

最后,在项目目录下,运行以下命令安装所有依赖项。

yarn install

Configure your project

在启动包中,我们提供了一个简单的项目配置示例。 您将主要处理以下文件:

  • The Manifest in project.yaml
  • The GraphQL Schema in schema.graphql
  • The Mapping functions in src/mappings/ directory

有关如何编写子查询的更多信息, 查看我们关于定义子查询的文档部分

Code generation

为了索引您的子查询项目,必须先构建您的项目。 在项目目录下运行此命令。

yarn codegen

Build the project

为了将您的 SubQuery 项目部署到我们的托管服务,必须在上传前打包您的配置。 从项目的根目录运行 pack 命令将自动生成一个 your-project-name.tgz 文件。

yarn build

Indexing and Query

Run required systems in docker

在项目目录下运行以下命令:

docker-compose pull && docker-compose up

Query the project

打开浏览器并前往 http://localhost:3000

最后,您应该会在资源管理器中看到一个 GraphQL playground 以及准备查询的模式。

对于subql-starter项目,您可以尝试使用以下代码进行查询,感受一下它的工作原理。

{
  query{
    starterEntities(first:10){
      nodes{
        field1,
        field2,
        field3
      }
    }
  }
}

SubQuery - Starter Package

The Starter Package is an example that you can use as a starting point for developing your SubQuery project. A SubQuery package defines which data The SubQuery will index from the Substrate blockchain, and how it will store it.

Preparation

Environment

  • Typescript are required to compile project and define types.

  • Both SubQuery CLI and generated Project have dependencies and require Node.

Install the SubQuery CLI

Install SubQuery CLI globally on your terminal by using NPM:

npm install -g @subql/cli

Run help to see available commands and usage provide by CLI

subql help

Initialize the starter package

Inside the directory in which you want to create the SubQuery project, simply replace project-name with your project name and run the command:

subql init --starter project-name

Then you should see a folder with your project name has been created inside the directory, you can use this as the start point of your project. And the files should be identical as in the Directory Structure.

Last, under the project directory, run following command to install all the dependency.

yarn install

Configure your project

In the starter package, we have provided a simple example of project configuration. You will be mainly working on the following files:

  • The Manifest in project.yaml
  • The GraphQL Schema in schema.graphql
  • The Mapping functions in src/mappings/ directory

For more information on how to write the SubQuery, check out our doc section on Define the SubQuery

Code generation

In order to index your SubQuery project, it is mandatory to build your project first. Run this command under the project directory.

yarn codegen

Build the project

In order to deploy your SubQuery project to our hosted service, it is mandatory to pack your configuration before upload. Run pack command from root directory of your project will automatically generate a your-project-name.tgz file.

yarn build

Indexing and Query

Run required systems in docker

Under the project directory run following command:

docker-compose pull && docker-compose up

Query the project

Open your browser and head to http://localhost:3000.

Finally, you should see a GraphQL playground is showing in the explorer and the schemas that ready to query.

For the subql-starter project, you can try to query with the following code to get a taste of how it works.

{
  query{
    starterEntities(first:10){
      nodes{
        field1,
        field2,
        field3
      }
    }
  }
}
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文