apollo-cache-inmemory
Advanced tools
Comparing version 1.3.9-beta.1 to 1.3.9
{ | ||
"name": "apollo-cache-inmemory", | ||
"version": "1.3.9-beta.1", | ||
"version": "1.3.9", | ||
"description": "Core abstract of Caching layer for Apollo Client", | ||
@@ -64,3 +64,4 @@ "author": "James Baxley <james@meteor.com>", | ||
"testURL": "http://localhost" | ||
} | ||
}, | ||
"gitHead": "9e7f06b856b133216bb639f787d8da81a6ab2df4" | ||
} |
@@ -9,2 +9,3 @@ import gql, { disableFragmentWarnings } from 'graphql-tag'; | ||
import { defaultDataIdFromObject } from '../inMemoryCache'; | ||
import { NormalizedCache } from '../types'; | ||
@@ -1029,2 +1030,102 @@ const fragmentMatcherFunction = new HeuristicFragmentMatcher().match; | ||
}); | ||
describe('issue #4081', () => { | ||
it('should not return results containing cycles', () => { | ||
const company = { | ||
__typename: 'Company', | ||
id: 1, | ||
name: 'Apollo', | ||
users: [], | ||
}; | ||
company.users.push({ | ||
__typename: 'User', | ||
id: 1, | ||
name: 'Ben', | ||
company, | ||
}, { | ||
__typename: 'User', | ||
id: 2, | ||
name: 'James', | ||
company, | ||
}); | ||
const query = gql` | ||
query Query { | ||
user { | ||
...UserFragment | ||
company { | ||
users { | ||
...UserFragment | ||
} | ||
} | ||
} | ||
} | ||
fragment UserFragment on User { | ||
id | ||
name | ||
company { | ||
id | ||
name | ||
} | ||
} | ||
`; | ||
function check(store: NormalizedCache) { | ||
const { result } = reader.diffQueryAgainstStore({ store, query }); | ||
// This JSON.stringify call has the side benefit of verifying that the | ||
// result does not have any cycles. | ||
const json = JSON.stringify(result); | ||
company.users.forEach(user => { | ||
expect(json).toContain(JSON.stringify(user.name)); | ||
}); | ||
expect(result).toEqual({ | ||
user: { | ||
id: 1, | ||
name: 'Ben', | ||
company: { | ||
id: 1, | ||
name: 'Apollo', | ||
users: [{ | ||
id: 1, | ||
name: 'Ben', | ||
company: { | ||
id: 1, | ||
name: 'Apollo', | ||
}, | ||
}, { | ||
id: 2, | ||
name: 'James', | ||
company: { | ||
id: 1, | ||
name: 'Apollo', | ||
}, | ||
}], | ||
}, | ||
}, | ||
}); | ||
} | ||
// Check first using generated IDs. | ||
check(writer.writeQueryToStore({ | ||
query, | ||
result: { | ||
user: company.users[0], | ||
}, | ||
})); | ||
// Now check with __typename-specific IDs. | ||
check(writer.writeQueryToStore({ | ||
dataIdFromObject: defaultDataIdFromObject, | ||
query, | ||
result: { | ||
user: company.users[0], | ||
}, | ||
})); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
526968
89
10706
0