Skip to content

Commit ab00709

Browse files
committed
integrationTests: add Flow test
1 parent 711425e commit ab00709

File tree

5 files changed

+78
-1
lines changed

5 files changed

+78
-1
lines changed

integrationTests/flow/.flowconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[include]
2+
./index.mjs
3+
4+
[declarations]
5+
.*/node_modules/.*
6+
7+
[options]
8+
include_warnings=true

integrationTests/flow/index.mjs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// @flow strict
2+
3+
import { parse } from 'graphql/language';
4+
import { GraphQLString, GraphQLSchema, GraphQLObjectType } from 'graphql/type';
5+
import { type ExecutionResult, execute } from 'graphql/execution';
6+
import { graphqlSync } from 'graphql';
7+
8+
interface SomeExtension {
9+
number: number;
10+
string: string;
11+
}
12+
13+
const example: SomeExtension = {
14+
number: 42,
15+
string: 'Meaning of life',
16+
};
17+
18+
const queryType: GraphQLObjectType = new GraphQLObjectType({
19+
name: 'Query',
20+
fields: {
21+
sayHi: {
22+
type: GraphQLString,
23+
args: {
24+
who: {
25+
type: GraphQLString,
26+
extensions: {
27+
someArgumentExtension: example,
28+
},
29+
},
30+
},
31+
resolve: (_root, args) => 'Hello ' + (args.who || 'World'),
32+
extensions: {
33+
someFieldExtension: example,
34+
},
35+
},
36+
},
37+
extensions: {
38+
someObjectExtension: example,
39+
},
40+
});
41+
42+
const schema: GraphQLSchema = new GraphQLSchema({
43+
query: queryType,
44+
});
45+
46+
const result: ExecutionResult = graphqlSync({
47+
schema,
48+
source: `
49+
query helloWho($who: String){
50+
test(who: $who)
51+
}
52+
`,
53+
variableValues: { who: 'Dolly' },
54+
});

integrationTests/flow/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"test": "flow check"
5+
},
6+
"dependencies": {
7+
"graphql": "file:../graphql.tgz",
8+
"flow-bin": "0.135.0"
9+
}
10+
}

integrationTests/integration-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ describe('Integration Tests', () => {
3939
testOnNodeProject('ts');
4040
}).timeout(40000);
4141

42+
it('Should compile with Flow', () => {
43+
testOnNodeProject('flow');
44+
}).timeout(10000);
45+
4246
it('Should work on all supported node versions', () => {
4347
testOnNodeProject('node');
4448
}).timeout(40000);

resources/build-npm.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ if (require.main === module) {
1919

2020
fs.mkdirSync(path.dirname(destPath), { recursive: true });
2121
if (filepath.endsWith('.js')) {
22-
fs.copyFileSync(srcPath, destPath + '.flow');
22+
const flowBody = '// @flow strict\n' + fs.readFileSync(srcPath, 'utf-8');
23+
fs.writeFileSync(destPath + '.flow', flowBody);
2324

2425
const cjs = babelBuild(srcPath, { envName: 'cjs' });
2526
fs.writeFileSync(destPath, cjs);

0 commit comments

Comments
 (0)