GraphQL LogoGraphQL

graphql-http

官方的 graphql-http 提供了一种简单的方法来创建完全符合 GraphQL 规范的服务器。它包含一个用于 Node.js 原生 http 的处理程序,以及用于知名框架(如 ExpressFastifyKoa)的处理程序;以及用于不同运行时(如 DenoBun)的处理程序。

Express#

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

createHandler#

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

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

查看 教程 获取示例用法。

查看 GitHub README 获取更详细的文档,包括如何将 graphql-http 与其他服务器框架和运行时一起使用。

继续阅读 →graphql