接口文档

schema 中 docstring 在生成的 type 和文档中会自动带上。

note:

参考 https://www.apollographql.com/docs/apollo-server/schema/schema/#descriptions-docstrings

"Description for the type"
type MyObjectType {
  """
  Description for field
  Supports **multi-line** description for your [API](<http://example.com>)!
  """
  myField: String!

  otherField(
    "Description for argument"
    arg: Int
  )
}

通用逻辑

Untitled

graphql 处理请求的流程和普通 http 请求大体来说流程是一样的。

使用上:

router.use(middleware)
const apolloServer = new ApolloServer({
  schema,
  plugins: [
		// ... plugin
  ],
})

Apollo Plugin

Overview

插件整体有两个 hook。分别是 server 创建时和每个请求。

export interface ApolloServerPlugin<
  TContext extends BaseContext = BaseContext,
> {
  serverWillStart?(
    service: GraphQLServiceContext,
  ): Promise<GraphQLServerListener | void>;

  requestDidStart?(
    requestContext: GraphQLRequestContext<TContext>,
  ): Promise<GraphQLRequestListener<TContext> | void>;
}