Skip to content

Commit d288b8b

Browse files
authored
make globalGqlIdentifierName case sensitive (#5945)
* Global Identifiers are forced lower case Global identifiers are converted to lower case before being used in this file. This patch corrects the comparison function to so they match in the file if the source identifier is not all lower case * Prettier & Tests * Update graphql-tag-pluck.mdx * Change to be case sensitive - don't lower case any globalGqlIdentifierNames
1 parent 27a32bc commit d288b8b

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

packages/graphql-tag-pluck/src/visitor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export default (code: string, out: any, options: GraphQLTagPluckOptions = {}) =>
203203
identifier: mod.identifier && mod.identifier.toLowerCase(),
204204
};
205205
});
206-
globalGqlIdentifierName = asArray(globalGqlIdentifierName).map(s => s!.toLowerCase());
206+
globalGqlIdentifierName = asArray(globalGqlIdentifierName ?? '');
207207

208208
const hooksOptions = { skipIndent, gqlMagicComment, modules, globalGqlIdentifierName };
209209

packages/graphql-tag-pluck/tests/graphql-tag-pluck.test.ts

+33-1
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,6 @@ describe('graphql-tag-pluck', () => {
19431943
globalGqlIdentifierName: 'anothergql',
19441944
},
19451945
);
1946-
19471946
expect(sources.map(source => source.body).join('\n\n')).toEqual(
19481947
freeText(`
19491948
fragment Foo on FooType {
@@ -1959,6 +1958,39 @@ describe('graphql-tag-pluck', () => {
19591958
);
19601959
});
19611960

1961+
it('should be able to specify the global GraphQL identifier name case sensitively', async () => {
1962+
const sources = await pluck(
1963+
'tmp-XXXXXX.js',
1964+
freeText(`
1965+
const fragment = anotherGql(\`
1966+
fragment Foo on FooType {
1967+
id
1968+
}
1969+
\`)
1970+
1971+
const doc = AnotherGql\`
1972+
query foo {
1973+
foo {
1974+
...Foo
1975+
}
1976+
}
1977+
1978+
\${fragment}
1979+
\`
1980+
`),
1981+
{
1982+
globalGqlIdentifierName: 'anotherGql',
1983+
},
1984+
);
1985+
1986+
expect(sources.map(source => source.body).join('\n\n')).toEqual(
1987+
freeText(`
1988+
fragment Foo on FooType {
1989+
id
1990+
}`),
1991+
);
1992+
});
1993+
19621994
it('should be able to specify the GraphQL magic comment to look for', async () => {
19631995
const sources = await pluck(
19641996
'tmp-XXXXXX.js',

website/src/pages/docs/graphql-tag-pluck.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ be translated into `/* GraphQL */` in code.
103103

104104
### `globalGqlIdentifierName`
105105

106-
Allows using a global identifier instead of a module import.
106+
Allows using a global identifier instead of a module import. Identifiers are case sensitive.
107107

108108
```js
109109
// `graphql` is a global function

0 commit comments

Comments
 (0)