Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Latest commit

 

History

History
executable file
·
71 lines (51 loc) · 1.88 KB

graphql.zh-CN.md

File metadata and controls

executable file
·
71 lines (51 loc) · 1.88 KB

本文档假设你已经了解 GraphQL 的基础知识, 如果你对它还不太了解,请参考 https://www.howtographql.com/

概况

CPS 所有接口提供,并且只提供 GraphQL 接口。所有 GraphQL 请求只能在两个地方发起:

  1. 在 pages 目录下,为页面的服务端渲染准备数据。
  2. 在每个容器组件的 logic.js 文件中(相应的 schema 文件位于同目录下)

怎样使用

containers/PostsThread/schema.js 为例:

import gql from 'graphql-tag'
import { P, F } from '@/schemas'

const pagedPosts = gql`
  ${P.pagedPosts}
`
const pagedArticleTags = gql`
  ${P.pagedArticleTags}
`

const pagedCommunities = gql`
  query($filter: CommunitiesFilter!) {
    pagedCommunities(filter: $filter) {
      entries {
        ${F.community}
        contributesDigest
        subscribersCount
      }
      ${F.pagi}
    }
  }
`

const schema = {
  pagedPosts,
  pagedArticleTags,
  pagedCommunities,
}

export default schema

P, F 均为公用 schema 片段(注意不是严格意义上的 Fragment, 但很类似)。导出 Schema 后可以在同目录的 logic.js 中使用:

const loadCityCommunities = () => {
  ....
  sr71$.query(S.pagedCommunities, args)
  ....
}

API 文档

你可以打开 https://coderplanets.com/graphiql 使用在线互动的工具,查询和使用 API

image

详细用法请参考文档

注意: 如果您要开发第三方的客户端请不要直接使用主站进行调试,开发请使用 https://dev.coderplanets.com

模型可视化

你可以打开 https://coderplanets.com/model-graphs 可视化的查看 model 之间的关系:

image