# push
After fetching (fetch
action) and changing (save
action) a record via Vuex-ORM you probably want to save it back to
your server via GraphQL. For this use case we have the push
action.
Via calling
const post = Post.query().first();
await post.$push();
// or
await post.$dispatch('push', { data: post });
the post record is send to the GraphQL by generating the following query:
mutation UpdatePost($id: ID!, $post: PostInput!) {
updatePost(id: $id, post: $post) {
id
userId
content
title
user {
id
email
}
}
}
Variables:
{
"id": "42",
"post": {
"id": "42",
"userId": "15",
"content": "Some more exciting content!",
"title": "Not a example post",
"user": {
"id": "15",
"email": "example@example.com"
}
}
}
Like when persisting, all records which are returned replace the respective existing records in the Vuex-ORM database.
# Additional variables
You can pass a object like this: $push({ captchaToken: 'asdfasdf' })
. All fields in the object will be passed as
variables to the mutation.
# Relationships
When pushing a record, all belongsTo
relations are sent to the server too. hasMany
/hasOne
relations on the other hand are filtered out and have to be persisted on their own.