Skip to content

Commit

Permalink
change to error and add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
finnigantime committed Apr 22, 2019
1 parent 07319ee commit 5b7e59d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/operations/SnapshotEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ export class SnapshotEditor {
}

if (this._context.addTypename && payloadName === '__typename') {
warnings.push(`Encountered undefined payload value for __typename which will override __typename value on existing fragment.`);
const message = `Encountered undefined payload value for __typename which will override __typename value on existing fragment`;
throw new InvalidPayloadError(message, prefixPath, containerId, path, payload);
}
}

Expand Down
37 changes: 37 additions & 0 deletions test/unit/Apollo/writeFragment/errorMissingTypename.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import gql from 'graphql-tag';

import { Hermes } from '../../../../src/apollo/Hermes';
import { strictConfig } from '../../../helpers/context';
import { StaticNodeId } from '../../../../src/schema';

const { QueryRoot: QueryRootId } = StaticNodeId;

describe(`writeFragment with missing __typename`, () => {

let hermes: Hermes;
beforeAll(() => {
hermes = new Hermes({
...strictConfig,
addTypename: true,
});
});

it(`throws an error`, () => {
expect(() => {
hermes.writeFragment({
id: QueryRootId,
fragment: gql(`
fragment viewer on Viewer {
id
name
}
`),
data: {
id: 123,
name: 'Gouda',
},
});
}).to.throw(/InvalidPayloadError: Encountered undefined payload value for __typename/i);
});

});

0 comments on commit 5b7e59d

Please sign in to comment.