diff --git a/CHANGELOG.md b/CHANGELOG.md index 7698f45bd12..19da14913bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/graphql-tag-pluck/src/config.ts b/packages/graphql-tag-pluck/src/config.ts index fa36f3360e0..01cf9e9d6d7 100644 --- a/packages/graphql-tag-pluck/src/config.ts +++ b/packages/graphql-tag-pluck/src/config.ts @@ -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) { diff --git a/packages/graphql-tag-pluck/tests/graphql-tag-pluck.test.ts b/packages/graphql-tag-pluck/tests/graphql-tag-pluck.test.ts index 38de72e8a9b..d2cc4693ff8 100644 --- a/packages/graphql-tag-pluck/tests/graphql-tag-pluck.test.ts +++ b/packages/graphql-tag-pluck/tests/graphql-tag-pluck.test.ts @@ -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');