-
-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(graphcache): track types in the data-structure #3501
Conversation
🦋 Changeset detectedLatest commit: 8125b32 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -170,18 +170,27 @@ export class Store< | |||
|
|||
invalidate(entity: Entity, field?: string, args?: FieldArgs) { | |||
const entityKey = this.keyOfEntity(entity); | |||
const shouldInvalidateType = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should narrow this down to only supporting invalidate({ __typename: 'Todo' })
as this explicitly can't derive a key nor be a global-id which can be the case with invalidate('x')
.
EDIT: getting quite sure it's safer to just do { __typename: 'X' }
as with global-ids we would other wise have to check whether the resulting key is present in the cache and assume it's a typename when not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be problematic if people accidentally pass invalidate
an entity that happens to be embedded.
This would issue warnings in other places, but if ignored, sometimes, given incomplete fragments for instance, a user could accidentally pass an object that contains no key fields just in that moment.
However, we could allow invalidate('TypeName')
, since we can check for types.has(typeName)
pretty easily now.
I see below though that we check for Object.keys(x).length
. I'm not sure if there's ever a case where someone wants to pass cache.invalidate({ __typename: 'X' })
over just a string?
Might be API-bloat 🤔 Unsure
02f103e
to
556d575
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing that stops us from merging ❤️ All just nit comments and follow-up questions
@@ -238,6 +240,7 @@ export const make = (queryRootKey: string): InMemoryData => ({ | |||
hydrating: false, | |||
defer: false, | |||
gc: new Set(), | |||
types: new Map(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this could potentially be faster in some cases as a normal object. That's because, while we avoid objects for entity key properties, using objects for anything predictable (field names and type names) should potentially be faster
@@ -170,18 +170,27 @@ export class Store< | |||
|
|||
invalidate(entity: Entity, field?: string, args?: FieldArgs) { | |||
const entityKey = this.keyOfEntity(entity); | |||
const shouldInvalidateType = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be problematic if people accidentally pass invalidate
an entity that happens to be embedded.
This would issue warnings in other places, but if ignored, sometimes, given incomplete fragments for instance, a user could accidentally pass an object that contains no key fields just in that moment.
However, we could allow invalidate('TypeName')
, since we can check for types.has(typeName)
pretty easily now.
I see below though that we check for Object.keys(x).length
. I'm not sure if there's ever a case where someone wants to pass cache.invalidate({ __typename: 'X' })
over just a string?
Might be API-bloat 🤔 Unsure
Co-authored-by: Phil Pluckthun <[email protected]>
Co-authored-by: Phil Pluckthun <[email protected]>
Co-authored-by: Phil Pluckthun <[email protected]>
0249a91
to
69a6d97
Compare
Related to #3470
Summary
This starts tracking a mapping of
__typename
to a list ofentityKey
, this enables us to perform operations likeinvalidate('Todo')
which would invalidate everyentityKey
of theTodo
type.We add non-root typenames when going through the
write
operation and we clean up entities in the list when we are going throughgc
runs.In the future this can instruct us for operations where we can't derive an entity i.e. a create-mutation will invalidate all entities of its own type to ensure we don't run into stale values which leaves us with the scalar return case which won't automatically be handled.
The PR explicitly does not add the
updater
logic yet so we can see that the explicit API surface does not grow, we support more cases instead.Set of changes
__typename
to a list of keysinvalidate('Type')
andinavlidate({ __typename: 'Type' })
Questions
Should we support invalidating a full type with field and arguments i.e.
invalidate('Todo', 'author')
would go through everyTodo
key and explicitly invalidate theAuthor
field.Follow-ups
invalidate({__typename})