graphql-from-swagger
🍇 Swagger 하나로 GraphQL 관련 코드를 생성해주는 CLI입니다.
개요
간단한 설정 파일 하나와 명령어 하나로 Swagger를 통해 GraphQL 관련 코드를 생성해주는 CLI입니다.
Input
- Swagger
Output
- GraphQL Schema
- Schema Type Definition
- RESTDataSource(apollo-datasource-rest) Child Class
- GraphQL Resolvers
CLI Usage
$ npx graphql-from-swagger
혹은
$ npm i -g graphql-from-swagger$ graphql-from-swagger
Config
프로젝트 루트 디렉토리에 graphql-from-swagger.config.json
파일을 생성합니다.
다음은 예시 설정 파일입니다.
설정을 위한 5가지 변수가 있습니다.
field | type | description | ext |
---|---|---|---|
swaggerPaths | string[] | swagger.json 혹은 swagger.yaml 파일의 경로 혹은 url입니다. | .json |
schemaOutputFiles | string[] | swagger를 통해 생성될 GraphQL Schema 파일의 경로입니다. | .graphql |
typesOutputFiles | string[] | GraphQL Schema를 통해 생성될 Type Definition 파일의 경로입니다. | .ts |
restDataSourceOutputFiles | string[] | RESTDataSource(apollo-datasource-rest)의 자식클래스 파일의 경로입니다. | .ts |
resolversOutputFiles | string[] | 생성될 resolvers 파일의 경로입니다. | .ts |
Dependencies
swagger
를 통해 GraphQL Schema를 생성할 때swagger-to-graphql
라이브러리를 사용합니다.- GraphQL Schema를 통해 Typescript Type Definition 파일을 생성할 때
@graphql-codegen/typescript
라이브러리를 사용합니다.
License
MIT