首页
/ Graphcool 模板项目使用教程

Graphcool 模板项目使用教程

2024-09-08 06:20:53作者:薛曦旖Francesca

1. 项目的目录结构及介绍

Graphcool 模板项目的目录结构如下:

graphcool-templates/
├── auth/
│   ├── email-password/
│   └── facebook/
├── messaging/
│   ├── mailgun/
│   ├── pusher/
│   └── twilio/
├── misc/
├── outdated/
├── .gitignore
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
└── templates.json

目录结构介绍

  • auth/: 包含用于不同认证机制的模板,如 email-password 或 facebook。
  • messaging/: 包含用于快速集成不同消息服务的模板,如 mailgun(电子邮件)、pusher(推送通知)或 twilio(短信)。
  • misc/: 包含其他杂项模板。
  • outdated/: 包含已过时的模板,这些模板不再被官方支持。
  • .gitignore: Git 忽略文件。
  • CODE_OF_CONDUCT.md: 项目的行为准则。
  • LICENSE: 项目的开源许可证。
  • README.md: 项目的介绍和使用说明。
  • templates.json: 模板配置文件。

2. 项目的启动文件介绍

Graphcool 模板项目没有传统的“启动文件”,因为这些模板主要是用于快速集成到 Graphcool 服务中。每个模板目录下通常包含以下文件:

  • graphcool.yml: 定义了模板的服务配置。
  • types.graphql: 定义了模板的数据模型。

示例:email-password 模板

auth/
└── email-password/
    ├── graphcool.yml
    └── types.graphql
  • graphcool.yml: 定义了 email-password 认证机制的服务配置。
  • types.graphql: 定义了 email-password 认证机制的数据模型。

3. 项目的配置文件介绍

graphcool.yml

graphcool.yml 文件是每个模板的核心配置文件,定义了服务的基本配置和功能。以下是一个示例:

# graphcool.yml

service: email-password-auth

types: ./types.graphql

permissions:
  - operation: "*"

hooks:
  - type: resolver
    name: signup
    query: ./src/signup.graphql

types.graphql

types.graphql 文件定义了模板的数据模型。以下是一个示例:

# types.graphql

type User {
  id: ID! @unique
  email: String! @unique
  password: String!
}

templates.json

templates.json 文件列出了所有可用的模板及其路径:

{
  "templates": [
    {
      "name": "email-password",
      "path": "auth/email-password"
    },
    {
      "name": "facebook",
      "path": "auth/facebook"
    },
    {
      "name": "mailgun",
      "path": "messaging/mailgun"
    }
  ]
}

通过以上配置文件,用户可以快速了解和使用 Graphcool 模板项目中的各种功能。

登录后查看全文
热门项目推荐