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 コンバーターを使用できます。