diff --git a/integrationTests/flow/.flowconfig b/integrationTests/flow/.flowconfig new file mode 100644 index 0000000000..872c3947a6 --- /dev/null +++ b/integrationTests/flow/.flowconfig @@ -0,0 +1,8 @@ +[include] +./index.mjs + +[declarations] +.*/node_modules/.* + +[options] +include_warnings=true diff --git a/integrationTests/flow/index.mjs b/integrationTests/flow/index.mjs new file mode 100644 index 0000000000..ee14390b35 --- /dev/null +++ b/integrationTests/flow/index.mjs @@ -0,0 +1,54 @@ +// @flow strict + +import { parse } from 'graphql/language'; +import { GraphQLString, GraphQLSchema, GraphQLObjectType } from 'graphql/type'; +import { type ExecutionResult, execute } from 'graphql/execution'; +import { graphqlSync } from 'graphql'; + +interface SomeExtension { + number: number; + string: string; +} + +const example: SomeExtension = { + number: 42, + string: 'Meaning of life', +}; + +const queryType: GraphQLObjectType = new GraphQLObjectType({ + name: 'Query', + fields: { + sayHi: { + type: GraphQLString, + args: { + who: { + type: GraphQLString, + extensions: { + someArgumentExtension: example, + }, + }, + }, + resolve: (_root, args) => 'Hello ' + (args.who || 'World'), + extensions: { + someFieldExtension: example, + }, + }, + }, + extensions: { + someObjectExtension: example, + }, +}); + +const schema: GraphQLSchema = new GraphQLSchema({ + query: queryType, +}); + +const result: ExecutionResult = graphqlSync({ + schema, + source: ` + query helloWho($who: String){ + test(who: $who) + } + `, + variableValues: { who: 'Dolly' }, +}); diff --git a/integrationTests/flow/package.json b/integrationTests/flow/package.json new file mode 100644 index 0000000000..8a87590458 --- /dev/null +++ b/integrationTests/flow/package.json @@ -0,0 +1,10 @@ +{ + "private": true, + "scripts": { + "test": "flow check" + }, + "dependencies": { + "graphql": "file:../graphql.tgz", + "flow-bin": "0.135.0" + } +} diff --git a/integrationTests/integration-test.js b/integrationTests/integration-test.js index c0371f676e..9ccaddd736 100644 --- a/integrationTests/integration-test.js +++ b/integrationTests/integration-test.js @@ -39,6 +39,10 @@ describe('Integration Tests', () => { testOnNodeProject('ts'); }).timeout(40000); + it('Should compile with Flow', () => { + testOnNodeProject('flow'); + }).timeout(10000); + it('Should work on all supported node versions', () => { testOnNodeProject('node'); }).timeout(40000); diff --git a/resources/build-npm.js b/resources/build-npm.js index fbc26c73e2..38793cac67 100644 --- a/resources/build-npm.js +++ b/resources/build-npm.js @@ -19,7 +19,8 @@ if (require.main === module) { fs.mkdirSync(path.dirname(destPath), { recursive: true }); if (filepath.endsWith('.js')) { - fs.copyFileSync(srcPath, destPath + '.flow'); + const flowBody = '// @flow strict\n' + fs.readFileSync(srcPath, 'utf-8'); + fs.writeFileSync(destPath + '.flow', flowBody); const cjs = babelBuild(srcPath, { envName: 'cjs' }); fs.writeFileSync(destPath, cjs);