graphqljs-如何搜索枚举类型

时间:2019-01-05 06:40:47

标签: javascript graphql

我试图将枚举定义为字符串,但似乎仍然无法理解枚举,这会引发错误。我猜我在查询错误,但不确定如何正确执行。

定义:

capchas

我的查询:

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

我正在使用graphlq-query-builder

当我运行查询时,它返回:

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
    )

2 个答案:

答案 0 :(得分:2)

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.

答案 1 :(得分:-1)

绝对同意,从Typescript角度来看,它应该起作用,但是在GraphQL中,它是以另一种方式实现的,我不相信他们会改变它。

这里是article的一个不错的David Mraz。它将清除您的所有担忧。

您将在本文的底部看到解决问题的方法。 将整数作为值,然后使用两个选项:指定枚举值,不带引号或使用字符串,但使用变量。

顺便说一句,希望您能阅读整篇文章。