我想将.yaml
(OpenAPI)转换为GraphQL模式(即,生成schema.graphql
)并找到2个转换器(脚本),可以帮助我:
每个示例中都有一个独立的示例,但是由于我是JS的新手,因此无法正常工作。谁能在我的.yaml
文件上发布完整的说明,我应该运行哪个命令来运行这些存储库?
我为repo #1尝试过的事情:
$ git clone https://github.com/yarax/swagger-to-graphql
$ cd swagger-to-graphql/
$ npm i -g swagger-to-graphql
$ npm i -g graphql # to eliminate the error above
$ swagger-to-graphql --swagger=doc.yaml > types.graphql
$ #doc.yaml is my OpenAPI file that I use as the input
$ swagger-to-graphql (master) $ cat types.graphql
Error: Error opening file "/Users/alex/Dev/temp/swagger-to-graphql/$"
ENOENT: no such file or directory, open '/Users/alex/Dev/temp/swagger-to-graphql/$'
at ReadFileContext.callback (/usr/local/lib/node_modules/swagger-to-graphql/node_modules/json-schema-ref-parser/lib/resolvers/file.js:51:20)
at FSReqCallback.readFileAfterOpen [as oncomplete] (fs.js:230:13)
Error: ENOENT: no such file or directory, open '/Users/alex/Dev/temp/swagger-to-graphql/$' {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/Users/klinou/Dev/temp/swagger-to-graphql/$',
toJSON: [Function: errorToJSON],
inspect: [Function: errorToString]
}
然后我收到一个错误:
internal/modules/cjs/loader.js:626
throw err;
^
Error: Cannot find module 'graphql'
Require stack:
- /usr/local/lib/node_modules/swagger-to-graphql/lib/index.js
- /usr/local/lib/node_modules/swagger-to-graphql/bin/swagger2graphql
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/local/lib/node_modules/swagger-to-graphql/lib/index.js',
'/usr/local/lib/node_modules/swagger-to-graphql/bin/swagger2graphql'
]
我为回购2尝试过的东西:
$ git clone https://github.com/graphql-binding/graphql-binding-openapi
$ yarn add graphql-binding-openapi
$ cd example/
$ graphql get-schema
# output: project petstore - endpoint default - No changes
# replace the last line .graphqlconfig.yml
# definition: schema.yaml (to use my input file instead of a sample)
$ graphql get-schema
⚠ Error opening file "/Users/alex/Dev/graphql-binding-openapi/example/$"
答案 0 :(得分:0)
您已全局安装swagger-to-graphql
(与-g
一起安装了。)
因此,其对等依赖项也必须全局安装。
答案 1 :(得分:0)
我可以建议您使用github.com/ibm/openapi-to-graphql吗?如果您的OAS(或摇摇晃晃的)格式正确,您可以在数分钟内快速启动并运行GraphQL界面。
https://github.com/IBM/openapi-to-graphql/blob/master/README.md描述了CLI的工作方式。