Skip to content

Commit

Permalink
Update graphql tag pluck to include flow plugins whenever the code in…
Browse files Browse the repository at this point in the history
…cludes @flow (#1622)
  • Loading branch information
Giancarlo Anemone committed Jun 9, 2020
1 parent 188fb3d commit aa3042f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
[@danielrearden](https://github.com/danielrearden) in [#1003](https://github.com/ardatan/graphql-tools/pull/1391)
- Export `generateProxyingResolvers` from `@graphql-tools/wrap`.
- Fix `stitchSchemas` from `@graphql-tools/stitch` from the case there the typeDefs array is empty. [#1575](https://github.com/ardatan/graphql-tools/pull/1575)
- Fix @graphql-tools/graphql-tag-pluck for flow projects using // @flow strict-local

### 5.0.0

Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-tag-pluck/src/config.ts
Expand Up @@ -36,7 +36,7 @@ export default function generateConfig(
const flowPlugins = [['flow', { all: true }], 'flowComments'];

// If line has @flow header, include flow plug-ins
const dynamicFlowPlugins = /^\/\/ *@flow *\n/.test(code) || /^\/\* *@flow *\*\/ *\n/.test(code) ? flowPlugins : [];
const dynamicFlowPlugins = code.includes('@flow') ? flowPlugins : [];

const fileExt = getExtNameFromFilePath(filePath);
switch (fileExt) {
Expand Down
37 changes: 37 additions & 0 deletions packages/graphql-tag-pluck/tests/graphql-tag-pluck.test.ts
Expand Up @@ -429,6 +429,43 @@ describe('graphql-tag-pluck', () => {
}
`));
});

it('should pluck graphql-tag template literals from .js file with @flow strict-local', async () => {
const gqlString = await pluck('tmp-XXXXXX.js', freeText(`
// @flow strict-local
import gql from 'graphql-tag'
import { Document } from 'graphql'
const fragment: Document = gql\`
fragment Foo on FooType {
id
}
\`
const doc: Document = gql\`
query foo {
foo {
...Foo
}
}
\${fragment}
\`
`));

expect(gqlString).toEqual(freeText(`
fragment Foo on FooType {
id
}
query foo {
foo {
...Foo
}
}
`));
});

it('should NOT pluck graphql-tag template literals from .js file without a @flow header', async () => {
const fail = Error('Function did not throw');
Expand Down

0 comments on commit aa3042f

Please sign in to comment.