Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jamesreggio/6f1c0dd668cac26fd437ba8af22951de to your computer and use it in GitHub Desktop.
Save jamesreggio/6f1c0dd668cac26fd437ba8af22951de to your computer and use it in GitHub Desktop.
Regression test for loss of data with overlapping fragments in apollo-cache-hermes
import { GraphSnapshot } from '../../../../../src/GraphSnapshot';
import { createSnapshot } from '../../../../helpers';
describe(`overlapping fragments`, () => {
let snapshot: GraphSnapshot;
beforeAll(() => {
const cyclicRefQuery = `
query {
myDetailedBar {
...DetailedBarFragment
}
myFooOrBar {
...FooFragment
...BarFragment
}
}
fragment FooFragment on Foo {
id
payload
}
fragment BarFragment on Bar {
id
fizz
}
fragment DetailedBarFragment on Bar {
...BarFragment
payload
}
`;
const result = createSnapshot(
{
myDetailedBar: {
id: 'Bar:1',
fizz: 'buzz',
payload: 'huge',
},
myFooOrBar: {
id: 'Bar:1',
fizz: 'buzz',
},
},
cyclicRefQuery
);
snapshot = result.snapshot;
});
it(`writing an entity with overlapping fragment fields should not lose data`, () => {
const bar = snapshot.getNodeData('Bar:1');
expect(bar.id).to.eq('Bar:1');
expect(bar.fizz).to.eq('buzz');
expect(bar.payload).to.eq('huge');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment