Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mattkrick/cashay
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkrick committed Feb 22, 2017
2 parents 6f68388 + 53d8f17 commit a6670f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/normalize/__tests__/denormalizeStore-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,26 @@ test('flag sendToServer = true for array of objects', t => {
// getPostById -> keywordsMentioned -> word
t.true(context.operation.selectionSet.selections[0].selectionSet.selections[1].selectionSet.selections[0].sendToServer);
});

test('Same query with another argument', t => {
const rawQuery = `
query {
getCommentsByPostId {
_id
postId
content
}
}`;
const queryAST = parseAndInitializeQuery(rawQuery, clientSchema, idFieldName);
const context = buildExecutionContext(queryAST, {
variables: {"postId": "p126"},
coerceTypes,
getState: () => ({entities:{}, result: {getCommentsByPostId: {'"postId": "p123"':[]}}}),
idFieldName,
paginationWords,
schema: clientSchema
});
const actual = denormalizeStore(context);
const expected = {getCommentsByPostId:[{_id:null,postId:null,content:null}]}
t.deepEqual(actual, expected)
});
8 changes: 6 additions & 2 deletions src/normalize/denormalizeStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ const visitObject = (subState = {}, reqAST, parentTypeSchema, context, reduction
if (isPrimitive(nnFieldType.kind) || subState[fieldName] === null) {
reduction[aliasOrFieldName] = visitScalar(fieldState, context.coerceTypes[typeSchema.name])
} else {
if (nnFieldType.kind === LIST) {
reduction[aliasOrFieldName] = visitIterable(fieldState, field, typeSchema, context, aliasOrFieldName);
if ((nnFieldType.kind === LIST)) {
if (fieldState) {
reduction[aliasOrFieldName] = visitIterable(fieldState, field, typeSchema, context, aliasOrFieldName);
} else {
reduction[aliasOrFieldName] = [visitObject(fieldState, field, typeSchema, context)];
}
} else {
reduction[aliasOrFieldName] = visitObject(fieldState, field, typeSchema, context);
}
Expand Down

0 comments on commit a6670f8

Please sign in to comment.