I am trying to upload an image by calling a graphql endpoint. My project is using micronaut version 2.5.11 and the "io.micronaut.graphql:micronaut-graphql" dependency.
I am trying to follow the guideline of the following two responses an a similar question
- the first one shows how to build your own custom scalar that is basically like ApolloScalar.Upload - https://stackoverflow.com/a/58544058/4093110
- the second one shows hot to upload with the GraphQLSchemaGenerator vs the schema first approach, which is also my current setup - https://stackoverflow.com/a/61807357/4093110
What I am facing now is having issues to actually call the mutation via Postman or curl. I have seen some examples (https://stackoverflow.com/a/57404357/4093110 and others) of calling the mutation in the following way:
curl --location --request POST 'http://localhost:8080/graphql' \
--form 'operations="{\"query\": \"mutation($files: [FileUpload]!)
{testMultiFilesUpload(files:$files)}\", \"variables\": {\"files\": [null,null] } }"' \
--form 'map="{ \"file0\": [\"variables.files.0\"] , \"file1\":[\"variables.files.1\"]}"' \
--form 'file0=@"image1.jpg"' \
--form 'file1=@"image2.jpg"'
The request does not reach the mutation and the response I receive is:
{
"code": "INTERNAL_SERVER_ERROR",
"status": 500,
"message": "Could not process GraphQL request"
}
I am not sure, but I believe that the "operations" key might be also Apollo specific, so I have tried also different combinations of calling the mutations by providing the form-data key as "query" and the value as the mutation only, and others.
I am probably not understanding how to correctly call this using the form-data. To try to determine if I am not calling correctly the mutation or if there is an issue with my setup of the custom scalar, I have tried calling another query which I know is working using the form-data:
As GraphQl body or raw-data it is working:
curl --location --request POST 'http://localhost:8080/graphql' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"query test{ test( testFilter: { ids:
[\"f25af744-2f4e-11ed-a261-0242ac120002\"] }) {id}}\r\n","variables":{}}'
But whatever combination I tried for passing this as a form-data it does not work:
curl --location --request POST 'http://localhost:8080/graphql' \
--form 'query="query test\\r\\n { test( testFilter: { ids:
[\"02ec5aef-c19e-4403-b460-54a2539f82d9\"] }) {id}}"'
I am trying basically to find a way to specify what query/mutation I want to call via form-data using Micronaut and micronaut-graphql.
Is there any chance that the form-data call is not suppoted by micronaut-graphql at all? I have failed to find any information regarding this. And I also have a rest-endpoint using Micronaut that supports the form-data call passing a file, so it should not be Micronaut related. Or am I making the call wrong?