gpt4 book ai didi

javascript - 是否可以忽略 graphql 中与 @include 一起使用的所需类型

转载 作者:行者123 更新时间:2023-12-02 22:08:01 24 4
gpt4 key购买 nike

是否可以忽略所需的类型(在这种情况下,createCarEvent 的类型输入包含变量 $from 作为 String!)使用@include?我尝试使用 $from 作为 String 而不是 String! 但它导致了异常:

Variable "$from" of type "String" used in position expecting type "String!"

$isNeedCreateCarEvent 检查两个变量($from$to)是否存在。

mutation rejectBooking(... $from: String, $to: String, $isNeedCreateCarEvent: Boolean!) {
...
createCarEvent(
input: {
...
from: $from
to: $to
}
) @include(if: $isNeedCreateCarEvent) {
...eventItem
}

方案:

    input CarEventInput {
...
from: String!
to: String
}

最佳答案

如果 $isNeedCreateCarEventtrue,GraphQL 无法知道始终提供 $from,类型声明无法表达这一点 (并且您的调用代码不能保证这一点)。

如果您想让 $from$to 可选,您最好使用两种单独的突变,一种带有 createCarEvent,另一种不带有 $from$to .

如果这对您来说意味着太多重复(因为查询的其余部分),唯一的方法是在使用 $isNeedCreateCarEvent = false 时将参数声明为非空并将空字符串作为虚拟值传递.

关于javascript - 是否可以忽略 graphql 中与 @include 一起使用的所需类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59652934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com