-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: graphql-tag-pluck options (#1156)
* feat: implement config override * fix: tests working * fix: add basic and failing test * feat: work in progress custom tag test * fix: one test works without graphql-config, both fail with it * fix: test clsoer to working, having jest lifecycle issues * fix: tests working * fix: improving tests * feat: changeset * refactor for improving already good work 😍 Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
- Loading branch information
1 parent
0d3fe5b
commit 6ac42cf
Showing
5 changed files
with
137 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@graphql-eslint/eslint-plugin': minor | ||
--- | ||
|
||
Using configuration options for `graphql-tag-pluck` through `graphql-config` | ||
Allow setup custom `globalGqlIdentifierName`, `modules.identifier` and `gqlMagicComment` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/plugin/tests/processor-with-graphql-config.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Block, processor } from '../src/processor'; | ||
|
||
jest.mock('../src/graphql-config', () => ({ | ||
loadGraphQLConfig: jest.fn(() => ({ | ||
getDefault: () => ({ | ||
extensions: { | ||
graphqlTagPluck: { | ||
modules: [{ name: 'custom-gql-tag', identifier: 'custom' }], | ||
gqlMagicComment: 'CustoM', | ||
}, | ||
}, | ||
}), | ||
})), | ||
})); | ||
|
||
describe('processor.preprocess() with graphql-config', () => { | ||
const QUERY = 'query users { id }'; | ||
it('should find "custom" tag', () => { | ||
const code = ` | ||
import { custom } from 'custom-gql-tag' | ||
const fooQuery = custom\`${QUERY}\` | ||
`; | ||
const blocks = processor.preprocess(code, '') as Block[]; | ||
|
||
expect(blocks[0].text).toBe(QUERY); | ||
expect(blocks).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
filename: document.graphql, | ||
lineOffset: 2, | ||
offset: 77, | ||
text: query users { id }, | ||
}, | ||
import { custom } from 'custom-gql-tag' | ||
const fooQuery = custom\`query users { id }\` | ||
, | ||
] | ||
`); | ||
}); | ||
|
||
it('should find /* CustoM */ magic comment', () => { | ||
const code = `/* CustoM */ \`${QUERY}\``; | ||
const blocks = processor.preprocess(code, '') as Block[]; | ||
|
||
expect(blocks[0].text).toBe(QUERY); | ||
expect(blocks).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
filename: document.graphql, | ||
lineOffset: 0, | ||
offset: 16, | ||
text: query users { id }, | ||
}, | ||
/* CustoM */ \`query users { id }\`, | ||
] | ||
`); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
packages/plugin/tests/processor-without-graphql-config.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Block, processor } from '../src/processor'; | ||
|
||
describe('processor.preprocess() without graphql-config', () => { | ||
const QUERY = 'query users { id }'; | ||
it('should find "gql" tag', () => { | ||
const code = ` | ||
import { gql } from 'graphql' | ||
const fooQuery = gql\`${QUERY}\` | ||
`; | ||
const blocks = processor.preprocess(code, '') as Block[]; | ||
|
||
expect(blocks[0].text).toBe(QUERY); | ||
expect(blocks).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
filename: document.graphql, | ||
lineOffset: 2, | ||
offset: 64, | ||
text: query users { id }, | ||
}, | ||
import { gql } from 'graphql' | ||
const fooQuery = gql\`query users { id }\` | ||
, | ||
] | ||
`); | ||
}); | ||
|
||
it('should find /* GraphQL */ magic comment', () => { | ||
const code = `/* GraphQL */ \`${QUERY}\``; | ||
const blocks = processor.preprocess(code, '') as Block[]; | ||
|
||
expect(blocks[0].text).toBe(QUERY); | ||
expect(blocks).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
filename: document.graphql, | ||
lineOffset: 0, | ||
offset: 17, | ||
text: query users { id }, | ||
}, | ||
/* GraphQL */ \`query users { id }\`, | ||
] | ||
`); | ||
}); | ||
}); |