GraphQL LogoGraphQL 中文网

graphql-http

官方 graphql-http 提供了一种创建完全兼容的 GraphQL 服务器的简单方法。它有一个针对 Node.js 原生 http 的处理程序,以及针对 ExpressFastifyKoa 等知名框架的处理程序;以及不同运行时(如 DenoBun)的处理程序。

英:The official graphql-http package provides a simple way to create a fully compliant GraphQL server. It has a handler for Node.js native http, together with handlers for well-known frameworks like Express, Fastify and Koa; as well as handlers for different runtimes like Deno and Bun.

Express(Express)#

import { createHandler } from "graphql-http/lib/use/express" // ES6
const { createHandler } = require("graphql-http/lib/use/express") // CommonJS

createHandler(createHandler)#

createHandler({
schema: GraphQLSchema,
rootValue?: ?any,
context?: ?any,
formatError?: ?Function,
validationRules?: ?Array<any>,
}): Handler

基于 GraphQL 架构构造 Express 处理程序。

英:Constructs an Express handler based on a GraphQL schema.

有关示例用法,请参阅 tutorial

英:See the tutorial for sample usage.

请参阅 GitHub 自述文件 以获取更详细的文档,包括如何将 graphql-http 与其他服务器框架和运行时结合使用。

英:See the GitHub README for more extensive documentation, including how to use graphql-http with other server frameworks and runtimes.

继续阅读 →graphql
GraphQL 中文网 - 粤ICP备13048890号