graphqljs - how to search enum type

Viewed 202

I'm trying to define my enums as strings but it still seems to throw an error at how it doesn't understand the enum. I'm guessing I'm querying it wrong but I'm unsure how to do it correctly.

Definition:

status: {
    type: new graphql.GraphQLEnumType({
        name:
            "status",
        values:
        {
            "accepted":
            {
                value:
                    "accepted"
            },
            "pending":
            {
                value:
                    "pending"
            },
            "reviewing":
            {
                value:
                    "reviewing"
            },
        }
    })
},    

My query:

const payload =
    {
        account_id:
            instanced_accounts[0]._id,
        account_type:
            instanced_accounts[0].type,
        page:
            1,
        page_length:
            5,
        search_text:
            "",
        status:
            "accepted",
    }        
let query =
    new QueryBuilder(
        "retrieveContacts",
        payload
    )

I'm using graphlq-query-builder

When I run the query it returns:

"message": "Expected type status, found \"accepted\"; Did you mean the enum value accepted?"
2 Answers

Looks like there's an open issue for that here that's ten months old. Looking at the code, it doesn't seem like enums are supported. I doubt there's any viable workaround outside of monkey-patching the code. A query builder is a neat idea, but there's a ton of features that are commonly used in GraphQL (Fragments, Enums, Unions, Interfaces, and Directives, for example) and I would expect a complete query builder to support them all. It looks like this particular library is very limited in functionality and possibly no longer maintained. You may be better off writing the queries out yourself for now.

Absolutely agree that from the Typescript perspective it should work, but in GraphQL it's implemented in another way and I don't believe they will change it.

Here is a great article from David Mraz about it. It will clear all your concerns.

You'll see at the bottom of the article the way you could solve your issue. Having integers as values and then two options: specify enumerated values without the quotation or using strings but with variables.

By the way, I wish you could read the whole article.

Related