-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix fragment imports for near-operation-file with graphQLTag (#9301)
- Loading branch information
Showing
5 changed files
with
173 additions
and
2 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,5 @@ | ||
--- | ||
'@graphql-codegen/visitor-plugin-common': patch | ||
--- | ||
|
||
Fix fragment imports for near-operation-file with graphQLTag |
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
53 changes: 53 additions & 0 deletions
53
packages/plugins/other/visitor-plugin-common/tests/utils.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,53 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
import { flatten, groupBy, unique } from '../src/utils'; | ||
|
||
describe('utils', () => { | ||
describe('flatten', () => { | ||
it('should flatten a nested array', () => { | ||
const array = [ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
[7, 8, 9], | ||
]; | ||
const actual = flatten(array); | ||
const expected = [1, 2, 3, 4, 5, 6, 7, 8, 9]; | ||
expect(actual).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('groupBy', () => { | ||
it('should group by a property', () => { | ||
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | ||
const actual = groupBy(array, i => i % 2); | ||
const expected = { 0: [2, 4, 6, 8, 10], 1: [1, 3, 5, 7, 9] }; | ||
expect(actual).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('unique', () => { | ||
it('should return unique items when no key selector is passed', () => { | ||
const array = [1, 2, 3, 1, 2, 4]; | ||
const actual = unique(array); | ||
const expected = [1, 2, 3, 4]; | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should return unique items based on key selector', () => { | ||
const array = [ | ||
{ id: 1, name: 'Alice' }, | ||
{ id: 2, name: 'Bob' }, | ||
{ id: 1, name: 'Alice #2' }, | ||
{ id: 3, name: 'Charlie' }, | ||
]; | ||
|
||
const actual = unique(array, item => item.id); | ||
const expected = [ | ||
{ id: 1, name: 'Alice' }, | ||
{ id: 2, name: 'Bob' }, | ||
{ id: 3, name: 'Charlie' }, | ||
]; | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
}); | ||
}); |