nexus
v1.3.0
适用于 TypeScript 和 JavaScript 的声明式、代码优先和强类型 GraphQL 模式构建。
npm install nexus graphql
请注意,您还必须添加graphql
。 Nexus 将其作为对等依赖项固定。
graphql-js
类型互操作,它只是一个GraphQLSchema
apollo-server
、 graphql-middleware
等现有的社区解决方案。 import { queryType , stringArg , makeSchema } from 'nexus'
import { GraphQLServer } from 'graphql-yoga'
const Query = queryType ( {
definition ( t ) {
t . string ( 'hello' , {
args : { name : stringArg ( ) } ,
resolve : ( parent , { name } ) => `Hello ${ name || 'World' } !` ,
} )
} ,
} )
const schema = makeSchema ( {
types : [ Query ] ,
outputs : {
schema : __dirname + '/generated/schema.graphql' ,
typegen : __dirname + '/generated/typings.ts' ,
} ,
} )
const server = new GraphQLServer ( {
schema ,
} )
server . start ( ( ) => `Server is running on http://localhost:4000` )
更多示例可以在/examples
目录中找到:
您可以在此处找到 Nexus 的文档。
如果您一直遵循 SDL 优先的方法来构建 GraphQL 服务器,并且想要查看使用 GraphQL Nexus 编写的代码是什么样子,则可以使用SDL 转换器。