0

I have a query that expects an enum of FileType to be passed on.

{
    item(itemId: 123){
    page(limit: 5, filters: {fileType: PDF}) {
      row{
        id
        fileName
      }
    }
  }
}

The fileType filter PDF is expected to be a FileType enum. Below are the enum values.

CSV
PDF
EXCEL
DOC
DOCX
PPT
PPTX
PNG
JPG
TIFF
UNKNOWN

I have created an enum and am passing the value into my query below (Python 3.8.5):

class FileType(str, Enum):
    CSV = 'CSV'
    PDF = 'PDF'
    EXCEL = 'EXCEL'
    DOC = 'DOC'
    DOCX = 'DOCX'
    PPT = 'PPT'
    PPTX = 'PPTX'
    PNG = 'PNG'
    JPG = 'JPG'
    TIFF = 'TIFF'
    UNKNOWN = 'UNKNOWN'


vars = {
           "itemId": itemId,
           "limit": limit,
           "filters": {
               "fileType": json.dump(FileType.DOC)
           }
       }

When my code is run FileType.DOC is converted to "DOC" when I expect it to be DOC in the query like the example. How would I go about doing this?

I referenced the solutions in Serialising an Enum member to JSON but none of the would work for me.

Ryan
  • 21
  • 1
  • 2
    The block at the top of your post is not valid JSON. – Scott Hunter Jun 17 '21 at 15:31
  • You're right, it's part of a GraphQL query. I'm having trouble converting to valid JSON for the {fileType: PDF} part. Everything I try produces something like {fileType: "PDF"} instead. – Ryan Jun 17 '21 at 16:11

0 Answers0