Closed CrispenGari closed 1 year ago
I just figure out that the problem was with my client as i tested the API using postman
and worked
@CrispenGari would you mind to share your solution(sample code) because I get the same issue
@annibuliful Is your your API working when you test it with clients like Postman?
Not at all so i need your suggestion to test it without API testing like Postman, Insomnia because they don't work
I need to know which graphql client are you using, because the last time i faced this error, i realised that the problem wasn’t with my fastify graphql-sever but with my urql client on react native.
Is it possible to use just only fetch API? I'm following this article https://www.floriangaechter.com/posts/graphql-file-uploading/
Yes it is possible I tested it on my Graphql server and it seems to work without problems. You can follow along this is my graphql-sever
So I tested the file upload locally by creating a simple html
and javascript
file and in my html
i had the following
<body>
<input type="file" id="picture" />
<button id="button">Upload File</button>
</body>
In my javascript file i had the following code in it
let file = null;
document.getElementById("picture").addEventListener("change", (e) => {
file = e.target.files[0];
});
document.getElementById("button").addEventListener("click", async () => {
const formData = new FormData();
const map = `{"0":["variables.picture"]}`;
const operations = `{"query":"mutation UploadFile($picture: Upload!){ uploadFile(picture: $picture)}"}`;
formData.append("operations", operations);
formData.append("map", map);
formData.append("0", file);
console.log({ file });
const res = await fetch("http://localhost:3001/graphql", {
body: formData,
method: "post",
});
const data = res.json();
console.log({ data });
});
The url endpoint for my server was running locally at http://localhost:3001/graphql
I'm trying to do file uploads using a
fastify
server usingmercurius
,type-graphql
andmercurius-upload
plugin. Here is my server code:Here is my
PetResolver
Here in my
NewPetInputType
On the client I'm using
React-Native
andURQL
but when I submit to the file to the server I'm getting the following error.What maybe possibly the problem here?