【发布时间】:2019-06-03 21:05:07
【问题描述】:
我想将 .yaml (OpenAPI) 转换为 GraphQL 架构(即生成 schema.graphql)并找到 2 个可以帮助我的转换器(脚本):
- https://github.com/yarax/swagger-to-graphql
- https://github.com/graphql-binding/graphql-binding-openapi
每个都有一个独立的示例,但由于我是 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'
]
我为 repo #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/$"
【问题讨论】:
-
您看过自述文件中的示例了吗?
-
@Dom 哦,我明白了。
-
@SLaks 你能再看看这个问题吗?我已经添加了一些细节。
-
@Dom 你能再看看这个问题吗?我没有设法运行那个独立的例子。
标签: javascript graphql yarnpkg