glennreyes / graphpack

☄️ A minimalistic zero-config GraphQL server.

Home Page:https://codesandbox.io/s/k3qrkl8qlv

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flow support

mxstbr opened this issue · comments

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

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

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

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.

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',
  ],
};

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

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

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.