admin管理员组文章数量:1319480
I have a project that uses the convo GraphQL, Relay and Flow. Is there a way to use GraphQL schema to feed Flow so the React props can be typed without redeclaring the types?
For Relay I'm already using the script that generates two files: schema.json
and schema.graphql
. The Babel plugin uses schema.json
to translate the queries into javascript.
The other file, schema.graphql
looks similar to Flow syntax definition for types, but there are differences. I've tried once to import type {Definition} from "./schema.graphql"
from it but was failing silently.
I have a project that uses the convo GraphQL, Relay and Flow. Is there a way to use GraphQL schema to feed Flow so the React props can be typed without redeclaring the types?
For Relay I'm already using the script that generates two files: schema.json
and schema.graphql
. The Babel plugin uses schema.json
to translate the queries into javascript.
The other file, schema.graphql
looks similar to Flow syntax definition for types, but there are differences. I've tried once to import type {Definition} from "./schema.graphql"
from it but was failing silently.
- There is no ready-to-use way I'm aware about, but I think you can write babel-plugin for it by yourself – gyzerok Commented Apr 8, 2016 at 7:54
2 Answers
Reset to default 8The problem with that is GraphQL scalar-types can be used to represent values in various formats and they do not inherit from a base type you could fall back to for flow.
Scalar can not only verify a "string" but "string of 32 hexadecimal digits". It's not possible to declare this kind of type in flow.
Here are some alternatives: babel-plugin-typecheck, json-to-flow
So after a while I decided to tackle this since our project started to grow and we started to loosen our types. In the end the simplest solution has been to grab the printerSchema and modify it so it outputs flow friendly text, save it to a .js file and point libraries to there.
I'll try to post it in github in a later date
本文标签: javascriptIs it possible to use Graphql generated schema as Flow definitionsStack Overflow
版权声明:本文标题:javascript - Is it possible to use Graphql generated schema as Flow definitions? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742059255a2418481.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论