Reputation: 31
First of all I am new to using graphQL in Go. I am using it to communicate with Cyanite.ai to generate metadata about songs. I am successful in asking an upload link and uploadId using graphQL and subsequently uploading the song. the next step is to turn the uploaded song into a Cyanite library item using a graphQL mutation with the uploadId that was sent to me in the first graphQL mutation call. From the documentation the GraphQL to turn it in to a library item is:
mutation LibraryTrackCreateMutation($input: LibraryTrackCreateInput!) {
libraryTrackCreate(input: $input) {
__typename
... on LibraryTrackCreateSuccess {
createdLibraryTrack {
id
}
}
... on LibraryTrackCreateError {
code
message
}
}
}
with variables:
{ "input": { "uploadId": "change me", "title": "API Track" } }
I turn this into the following struct for the graphQL client (github.com/hasura/go-graphql-client):
type LibraryTrackCreateMutation struct {
LibraryTrackCreate struct {
Typename string `graphql:"__typename"`
CreatedLibraryTrack struct {
ID string `graphql:"id"`
} `graphql:"... on LibraryTrackCreateSuccess"`
Code string `graphql:"code ... on LibraryTrackCreateError"`
Message string `graphql:"message ... on LibraryTrackCreateError"`
} `graphql:"libraryTrackCreate(input: $input)"`
}
var libraryTrackMutation LibraryTrackCreateMutation
with variables:
variables := map[string]interface{}{
"input": map[string]interface{}{
"uploadId": uploadId,
"title": title,
},
}
I execute the mutation with graphQL client as follows:
grapQlError := graphQLClient.Mutate(context.Background(), &libraryTrackMutation, variables)
which returns the error:
Message: 422 Unprocessable Entity, Locations: [], Extensions: map[code:request_error], Path: []
When I execute the mutation in a GraphiQL graphical interface on the specific song uploaded the result is successful. Is my syntax incorrect for describing the mutation?
I tried changing the syntax, but since im no graphQL expert these were shots in the dark. I tried it on other mp3 files with the same result.
On a successful run the Cyanite.ai graphQL server should return
{
"data": {
"libraryTrackCreate": {
"__typename": "LibraryTrackCreateSuccess",
"createdLibraryTrack": {
"id": "21999304"
}
}
}
}
Upvotes: 1
Views: 12