Upload file mutation

Any hint or pattern for handling mutations with some binary data arguments to be stored as files ?

Hi @aleclofabbro, currently we don’t support storing data as a file in Dgraph but we will surely discuss it internally. Thanks for reaching out to us.

thanks @JatinDevDG,
I was thinking of a custom resolver that could manage uploaded file and execute proper graphql (e.g. storing file-url)
but I wonder how should I define schema for receiving binary over GraphQL

Currently we don’t have support for storing files or a byte datatype. You can try to use String datatype if that works in your use case.

The official GraphQL spec doesn’t define any type which can contain binary data. All the transport happens over HTTP in JSON. And, even in JSON there is no way that you can put binary data unless you want to put the byte string as a String in JSON. But, that would probably not be the best deal you might want, because that would be worse than using the decoded file contents as String. JSON has got UTF-8 character encoding support, so I think the best you can achieve ATM with this is to decode the file contents as a String and send it over as a parameter to some GraphQL query. That way you would be able to use String type in GraphQL to represent the file data. You can probably store the file type too along with the data on the GraphQL server.

But, then where do you want to store those files also decides how you should approach this problem. I see that you want to just store the file URL in Dgraph, and not the file contents itself. So, why not create a separate HTTP endpoint which can handle file upload, and then that endpoint internally makes a call to the GraphQL API to store the file URL once the file has been uploaded on that server.

4 Likes