Skip to content

Commit

Permalink
fix: Don't push multiple items whose text are same to valuesNotChange…
Browse files Browse the repository at this point in the history
…d list
  • Loading branch information
Quramy committed Mar 12, 2024
1 parent 7d83fd3 commit 56d10a6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
24 changes: 24 additions & 0 deletions src/gql-ast-util/fragment-registry.test.ts
Expand Up @@ -214,6 +214,30 @@ describe(DefinitionFileStore, () => {
});
});

describe('file1: ["A:0"] -> file1: ["A:0", "A:0"] -> file1: ["B:0", "A:0"]', () => {
let store: TestingStore;
beforeEach(() => {
store = createTestingStore();
store.update('main.ts', ['A:0']);
store.update('main.ts', ['A:0', 'A:0']);
store.update('main.ts', ['B:0', 'A:0']);
});

test('correct history', () => {
expect([...store.getDetailedAffectedDefinitions(2)[0].updated.values()]).toEqual([]);
expect([...store.getDetailedAffectedDefinitions(2)[0].appeared.values()]).toEqual(['B', 'A']);
expect([...store.getDetailedAffectedDefinitions(2)[0].disappeared.values()]).toEqual([]);
});

test('correct unique definition', () => {
expect([...store.getUniqueDefinitonMap().keys()]).toEqual(['B', 'A']);
});

test('correct duplicated definition', () => {
expect([...store.getDuplicatedDefinitonMap().keys()]).toEqual([]);
});
});

describe.each`
file1Docs | file2Docs | affected | unique | duplicated
${['A:0', 'B:0']} | ${['A:1']} | ${['B', 'A']} | ${['B']} | ${['A']}
Expand Down
8 changes: 3 additions & 5 deletions src/gql-ast-util/fragment-registry.ts
Expand Up @@ -135,11 +135,9 @@ export class DefinitionFileStore<T extends DefinitionAST, TExtra = unknown> {

for (const doc of documents) {
const alreadyParsedItems = currentValueMapByText.get(doc.text);
if (alreadyParsedItems) {
alreadyParsedItems.forEach(v => {
v.extra = doc.extra;
valuesNotChanged.push(v);
});
if (alreadyParsedItems && alreadyParsedItems.length === 1) {
alreadyParsedItems[0].extra = doc.extra;
valuesNotChanged.push(alreadyParsedItems[0]);
currentValueMapByText.delete(doc.text);
continue;
}
Expand Down

0 comments on commit 56d10a6

Please sign in to comment.