-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deduplicate fragment definition before codegen
Resolves #33
- Loading branch information
Showing
10 changed files
with
3,631 additions
and
94 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 |
---|---|---|
|
@@ -62,6 +62,7 @@ jspm_packages/ | |
/*.d.ts | ||
/workers | ||
!/babel.config.js | ||
!/jest.config.js | ||
!/index.js | ||
!/.pnp.js | ||
|
||
|
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,27 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { promisify } from 'util'; | ||
import { visit } from 'graphql'; | ||
import { deduplicateFragmentFromDocuments } from '~/src/common'; | ||
|
||
const readFile = promisify(fs.readFile); | ||
|
||
test('deduplicateFragmentFromDocuments()', async () => { | ||
const data = await readFile(path.resolve(__dirname, 'data/gh-33.json'), 'utf-8'); | ||
const documents = JSON.parse(data); | ||
const resultDocuments = deduplicateFragmentFromDocuments(documents); | ||
|
||
const fragmentNames = new Set<string>(); | ||
for (const { document } of resultDocuments) { | ||
visit(document, { | ||
FragmentDefinition(node) { | ||
const duplicated = fragmentNames.has(node.name.value); | ||
expect(duplicated).toBe(false); | ||
|
||
if (!duplicated) { | ||
fragmentNames.add(node.name.value); | ||
} | ||
}, | ||
}); | ||
} | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
module.exports = { | ||
verbose: true, | ||
transform: { | ||
'^.+\\.[t|j]sx?$': 'babel-jest', | ||
}, | ||
}; |
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
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
Oops, something went wrong.