I'm implementing a variation of the file upload in this tutorial:
https://strawberry.rocks/docs/guides/file-upload
The code is basically this:
import typing
import strawberry
from strawberry.file_uploads import Upload
@strawberry.input
class FolderInput:
files: typing.List[Upload]
@strawberry.type
class Mutation:
@strawberry.mutation
async def read_file(self, file: Upload) -> str:
[do some processing]
return "Processing of PDF done!"
I test it with this invocation:
curl localhost:8000/graphql \
-F operations='{ "query": "mutation($file: Upload!){ readFile(file: $file) }", "variables": { "file": null } }' \
-F map='{ "file": ["variables.file"] }' \
-F file=@/path/to/some_file.pdf
The CURL invocation calls readFile whereas the mutation in Strawberry uses read_file, where is that mapping done and can we control that? I'd like multiple read methods (e.g. read_typeA_pdf, read_typeB_pdf, etc).
To give my share of my knowledge on this is - the mapping between
the GraphQL mutation nameandthe actual Python method nameis handled by theStrawberrylibrary itselfAs per your example, I would say the GraphQL mutation name is
readFile, while the Python method name isread_file.Strawberryuses asnake_casenaming convention to convert the GraphQL operation name to a Python method nameyou can try directly as below
Possibly, With these methods defined, you can now use the following GraphQL mutation names to invoke them like below:
Invoking the
read_typeA_pdfmutation with a Type A PDF fileInvoking the
read_typeB_pdfmutation with a Type B PDF file:You might replace
/path/to/typeA.pdfand/path/to/typeB.pdfwith the actual paths to your Type A and Type B PDF files, respectively.https://strawberry.rocks/docs/general/mutations
Hope this helps.