graphql-from-swagger
Version:
<a href="http://badge.fury.io/js/graphql-from-swagger"><img src="https://badge.fury.io/js/graphql-from-swagger.svg"></a>
71 lines (47 loc) โข 2.72 kB
Markdown
<a href="http://badge.fury.io/js/graphql-from-swagger"><img src="https://badge.fury.io/js/graphql-from-swagger.svg"></a>
> ๐ Swagger ํ๋๋ก GraphQL ๊ด๋ จ ์ฝ๋๋ฅผ ์์ฑํด์ฃผ๋ CLI์
๋๋ค.

๊ฐ๋จํ ์ค์ ํ์ผ ํ๋์ ๋ช
๋ น์ด ํ๋๋ก Swagger๋ฅผ ํตํด GraphQL ๊ด๋ จ ์ฝ๋๋ฅผ ์์ฑํด์ฃผ๋ CLI์
๋๋ค.
* Swagger
* GraphQL Schema
* Schema Type Definition
* RESTDataSource(apollo-datasource-rest) Child Class
* GraphQL Resolvers
```bash
$ npx graphql-from-swagger
```
ํน์
```bash
$ npm i -g graphql-from-swagger
$ graphql-from-swagger
```
ํ๋ก์ ํธ ๋ฃจํธ ๋๋ ํ ๋ฆฌ์ `graphql-from-swagger.config.json` ํ์ผ์ ์์ฑํฉ๋๋ค.
๋ค์์ ์์ ์ค์ ํ์ผ์
๋๋ค.
```json
{
"swaggerPaths": ["test/swagger.json", "https://petstore.swagger.io/v2/swagger.json"],
"schemaOutputFiles": ["generated/heroes.graphql", "generated/petstore.graphql"],
"typesOutputFiles": ["generated/HeroesTypes.ts", "generated/PetstoreTypes.ts"],
"restDataSourceOutputFiles": ["generated/HeroesApi.ts", "generated/PetstoreApi.ts"],
"resolversOutputFiles": ["generated/HeroesResolvers.ts", "generated/PetstoreResolvers.ts"]
}
```
์ค์ ์ ์ํ 5๊ฐ์ง ๋ณ์๊ฐ ์์ต๋๋ค.
| field | type | description | ext |
|---------------------------|----------|----------------------------------------------------------------|---------------------|
| swaggerPaths | string[] | swagger.json ํน์ swagger.yaml ํ์ผ์ ๊ฒฝ๋ก ํน์ url์
๋๋ค. | .json | .yaml | url |
| schemaOutputFiles | string[] | swagger๋ฅผ ํตํด ์์ฑ๋ GraphQL Schema ํ์ผ์ ๊ฒฝ๋ก์
๋๋ค. | .graphql |
| typesOutputFiles | string[] | GraphQL Schema๋ฅผ ํตํด ์์ฑ๋ Type Definition ํ์ผ์ ๊ฒฝ๋ก์
๋๋ค. | .ts |
| restDataSourceOutputFiles | string[] | RESTDataSource(apollo-datasource-rest)์ ์์ํด๋์ค ํ์ผ์ ๊ฒฝ๋ก์
๋๋ค. | .ts |
| resolversOutputFiles | string[] | ์์ฑ๋ resolvers ํ์ผ์ ๊ฒฝ๋ก์
๋๋ค. | .ts |
* `swagger`๋ฅผ ํตํด GraphQL Schema๋ฅผ ์์ฑํ ๋ [`swagger-to-graphql`](https://github.com/yarax/swagger-to-graphql) ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
* GraphQL Schema๋ฅผ ํตํด Typescript Type Definition ํ์ผ์ ์์ฑํ ๋ [`@graphql-codegen/typescript`](https://graphql-code-generator.com/docs/plugins/typescript) ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
MIT