glennreyes / graphpack

☄️ A minimalistic zero-config GraphQL server.
https://codesandbox.io/s/k3qrkl8qlv
MIT License
1.99k stars 80 forks source link

Flow support #34

Open mxstbr opened 6 years ago

mxstbr commented 6 years ago

I see that graphpack supports TypeScript out of the box (#12), how about Flowtype? Would that only require adding a custom Babel configuration?

glennreyes commented 6 years ago

Yep I would say so. Add your .flowconfig and:

// babel.config.js
module.exports = {
  presets: ['graphpack/babel', '@babel/preset-flow'],
};
mxstbr commented 6 years ago

Can I somehow remove the built-in TypeScript support from graphpack/babel? I don't want that to accidentally interfere with any of the flow typings.

glennreyes commented 6 years ago

Oh good point! Well, since there's not much in graphpack/babel, you could just use what's in there and remove the TS preset:


// babel.config.js
module.exports = {
  plugins: ['@babel/plugin-syntax-dynamic-import'],
  presets: [
    ['@babel/preset-env', { targets: { node: 'current' }, modules: false }],
    '@babel/preset-flow',
  ],
};
mxstbr commented 6 years ago

I see, makes sense! Maybe it's worth making that an option?

module.exports = {
  presets: [
    [['graphpack/babel', { types: 'flow' | 'typescript' | false }]],
};
glennreyes commented 6 years ago

Ideally, Graphpack can detect whether there's a .flowconfig or tsconfig.json and adds babel presets accordingly. This way we wouldn't have to deal with babel config at all.