Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Graphql generated schema as Flow definitions?

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.

like image 273
Blai Pratdesaba Avatar asked Apr 08 '16 07:04

Blai Pratdesaba


Video Answer


1 Answers

The 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

like image 55
igl Avatar answered Sep 19 '22 09:09

igl