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 轉換器。