Skip to content

Commit

Permalink
Add a regression test for issue #4025 (fixed by PR #4038).
Browse files Browse the repository at this point in the history
As requested by @jbaxleyiii:
#4038 (comment)
  • Loading branch information
benjamn committed Oct 26, 2018
1 parent 9ad87d4 commit 2e70c99
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions packages/apollo-cache-inmemory/src/__tests__/diffAgainstStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -970,4 +970,59 @@ describe('diffing queries against the store', () => {
expect(result).toEqual(previousResult);
});
});

describe('malformed queries', () => {
it('throws for non-scalar query fields without selection sets', () => {
// Issue #4025, fixed by PR #4038.

const validQuery = gql`
query getMessageList {
messageList {
id
__typename
message
}
}
`;

const invalidQuery = gql`
query getMessageList {
# This field needs a selection set because its value is an array
# of non-scalar objects.
messageList
}
`;

const store = writer.writeQueryToStore({
query: validQuery,
result: {
messageList: [{
id: 1,
__typename: "Message",
message: "hi"
}, {
id: 2,
__typename: "Message",
message: "hello"
}, {
id: 3,
__typename: "Message",
message: "hey"
}]
}
});

try {
reader.diffQueryAgainstStore({
store,
query: invalidQuery,
});
throw new Error('should have thrown');
} catch (e) {
expect(e.message).toEqual(
'Missing selection set for object of type Message returned for query field messageList'
);
}
});
});
});

0 comments on commit 2e70c99

Please sign in to comment.