Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
(fix) - respect alternative rootkeys in query (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Sep 24, 2019
1 parent 0c2229a commit 9a51cbb
Show file tree
Hide file tree
Showing 3 changed files with 1,109 additions and 2 deletions.
34 changes: 33 additions & 1 deletion src/operations/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ const TODO_QUERY = gql`
`;

describe('Query', () => {
let schema, store;
let schema, store, alteredRoot;
const spy: { console?: any } = {};

beforeAll(() => {
schema = require('../test-utils/simple_schema.json');
alteredRoot = require('../test-utils/altered_root_schema.json');
});

afterEach(() => {
Expand Down Expand Up @@ -140,4 +141,35 @@ describe('Query', () => {
todos: [{ __typename: 'Todo', id: '0', text: 'Solve bug' }],
});
});

it('should respect altered root types', () => {
const QUERY = gql`
query getTodos {
todos {
id
text
}
}
`;

const store = new Store(new SchemaPredicates(alteredRoot));

let { data } = query(store, { query: QUERY });
expect(data).toEqual(null);

write(
store,
{ query: QUERY },
{
todos: [{ __typename: 'Todo', id: '0', text: 'Solve bug' }],
__typename: 'query_root',
}
);

({ data } = query(store, { query: QUERY }));
expect(data).toEqual({
__typename: 'query_root',
todos: [{ __typename: 'Todo', id: '0', text: 'Solve bug' }],
});
});
});
2 changes: 1 addition & 1 deletion src/operations/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const read = (

let data = input || Object.create(null);
data =
rootKey !== 'Query'
rootKey !== ctx.store.getRootKey('query')
? readRoot(ctx, rootKey, rootSelect, data)
: readSelection(ctx, rootKey, rootSelect, data);

Expand Down
Loading

0 comments on commit 9a51cbb

Please sign in to comment.