-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
The v1.3 works great so far, thanks for the work, I love the Relay integration.
Currently experience a problem, where when I want to update the cache after mutation.
In order to get the cache ref from the following query:
query TaskListQueryWrapperQuery($companyId: String) {
company_connection(where: { id: { _eq: $companyId } }) {
edges {
node {
...TaskList_company
}
}
}
}
fragment TaskList_company on company
@argumentDefinitions(
first: { type: "Int!", defaultValue: 50 }
after: { type: "String" }
cursor: { type: "String" }
)
@refetchable(queryName: "TaskListPaginationQuery") {
tasks_connection(first: $first, after: $after)
@connection(
key: "TaskList_tasks_connection"
filters: ["first", "after"]
) {
edges {
node {
id
...TaskListItem_task
}
}
}
}in the Relay updater function:
const tasks = store.get(
'WzEsICJwdWJsaWMiLCAiY29tcGFueSIsICJjb21wYW55X2NrYWt2MHRkaDAwMDEwOG1xMmJwczUxb2EiXQ==',
)
const connectionRecord = ConnectionHandler.getConnection(
tasks,
'TaskList_tasks_connection',
{ first: 50 },
)The problem is here: WzEsICJwdWJsaWMiLCAiY29tcGFueSIsICJjb21wYW55X2NrYWt2MHRkaDAwMDEwOG1xMmJwczUxb2EiXQ==,
- it is not my id, because my id follows the pattern of
entityName_cuid, like,company_cy23781nkdd. - it is a Hasura generated id for my
companyentity
So, 2 questions:
- how can I regenerate the id for an existing record, in this case, how can I generate this
WzEsICJwdWJsaWMiLCAiY29tcGFueSIsICJjb21wYW55X2NrYWt2MHRkaDAwMDEwOG1xMmJwczUxb2EiXQ==? - how can I regenerate the id for a new result after mutation? I need this to locate the record
I found in this PR: #4458 where @rakeshkky mentioned this:
The global unique id is base64 encoding of the JSON object which contains the details of the table name itself and primary key column values. The id is a primary key column whose value is encoded.
May I have some more info? @rakeshkky Thanks
Actually, I think just use tableName_id is sufficient enough to be a global unique id, because there are no two tables with the same name. Or I miss something. :)
One more
how to get the serverEdge, on Relay doc, they have an example of updating Relay store after mutation (code below).
// Get the payload returned from the server
const payload = store.getRootField('comment_create');
// Get the edge inside the payload
const serverEdge = payload.getLinkedRecord('comment_edge');However, in Hasura Schema:
mutation CreateTaskMutation($input: task_insert_input!) {
insert_task_one(object: $input) {
id
title
due_date
due_time
description
}
}the returned result is right after insert_task_one {}, there is no nesting edge here for wrapping it like the normal Hasura endpoint, there is an extra return {}, how could I get the serverEdge here? I wanted to recreate an new edge, but then I do not know the hasura generated id.
Thanks, it might be a tricky one, because it seems to be generated on the fly, not in the database.
Or I missing something here?
I posted an issue on their end: facebook/relay#3170 maybe I need to create one here?