I am using laravel-graphql as a backend GraphQL service and vue-apollo as a frontend client.
In my Vue component I have a gql query as follows: (relation: A Song has more SongParts)
const getSong = gql`
query FetchSong ($id:Int!){
song(id: $id) {
id,
name,
authors_lyrics,
authors_music
song_parts{
type
lyrics
}
}
}`;
Now there's a mutation that i want to use to update given song:
const updateSong = gql`
mutation updateSongMutation ($id:Int!,$name:String,$authors_lyrics:String,$authors_music:String, $song_parts: [SongPart]) {
updateSongMutation(id: $id, name: $name, authors_lyrics: $authors_lyrics, authors_music: $authors_music, song_parts: $song_parts) {
id
}
}`;
.. and in the Vue component used this way:
methods: {
save: function(){
this.$apollo.mutate({
mutation: updateSong,
variables: this.songData,
}).then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
})
}
},
However, to update the song_parts array I need to define a custom input type:
input SongPart{
id: Int!
lyrics: String
}
I can't figure out, where to define this input type. When I'm using GraphiQL in Chrome WebTools, there's no problem defining it in front of the mutation. I also found some info for apollo server, but I need it in the client.
So basically the problem is about mutating a list of data.
Your input types should still be defined inside your schema on the server. I'm not that familiar with laravel, but looking at the documentation for laravel-graphql, it looks like at the moment inputs are defined just like regular types, you just set the $inputObject property to true. See the example here. I would imagine you would then add them to your types inside config/graphql.php along with the regular types.
I would also suggest renaming the input to something like SongPartInput so you don't get confused if you also have a type for SongPart.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With