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 관련 문서를 찾을 수 있습니다.
GraphQL 서버를 구축하기 위해 SDL 우선 접근 방식을 따르고 있으며 GraphQL Nexus로 작성된 코드가 어떻게 보이는지 확인하려는 경우 SDL 변환기를 사용할 수 있습니다.