Push Query for RxDB

For the push query we use an upsert:

const pushQueryBuilder = doc => {
const query = `
mutation InsertTodo($todo: [todos_insert_input!]!) {
insert_todos(
objects: $todo,
on_conflict: {
constraint: todos_pkey,
update_columns: [text, isCompleted, deleted, updatedAt]
}){
returning {
id
}
}
}
`;
const variables = {
todo: doc
};
return {
query,
variables
};
};

RxDB will call the above method whenever a document is updated or a new document is created. RxDB will then fire the graphQL query returned along with the variables returned. In the above function the InsertTodo mutation tells hasura to try to insert the row only if a row with the same id does not already exist. If a row with the same id exists then Hasura will simply update the columns given in the update_columns field of that row.

Did you find this page helpful?
Start with GraphQL on Hasura for Free
  • ArrowBuild apps and APIs 10x faster
  • ArrowBuilt-in authorization and caching
  • Arrow8x more performant than hand-rolled APIs
Promo
footer illustration
Brand logo
© 2024 Hasura Inc. All rights reserved
Github
Titter
Discord
Facebook
Instagram
Youtube
Linkedin
graphql-handbook