gpt4 book ai didi

angular - Apollo + Angular 突变不适用于变量

转载 作者:行者123 更新时间:2023-12-05 06:58:12 24 4
gpt4 key购买 nike

我在使用变量创建突变时遇到了麻烦。我可以让它直接包含值,就像这样:

export const orderCancellation = gql`
mutation{
cancelOrder(input: {id: 2649, cancellationReasonId: 1 } ) {
order{
id,
isCancelled
}
}
}`;

但是当尝试使用变量时没有任何效果:

export const orderCancellation = gql`
mutation cancelOrder($id: ID!, $cancellationReasonId: ID!) {
cancelOrder(input: {id: $id, cancellationReasonId: $cancellationReasonId }) {
order {
id,
isCancelled
}
}
}`;

来 self 们服务器的自定义错误消息:

Didn't find any result for  'CancelOrderPayload' with the arguments '{:input=>#<#<Class:0x00005608dca67e90>:0x00005608e10cd790 @context=#<Query::Context ...>, @ruby_style_hash={:id=>nil, :cancellation_reason_id=>nil}, @arguments=#<GraphQL::Execution::Interpreter::Arguments @keyword_arguments={:id=>nil, :cancellation_reason_id=>nil}>, @maybe_lazies=[]>}.

这就是我对突变的称呼:

this.apollo.mutate({
mutation: orderCancellation,
variables: {id: orderId, cancellationReasonId: reasonId}
});

有人知道我做错了什么吗?可能是服务器端问题?

编辑 1:这是带有变量实现的请求负载(取自 Chrome DevTools 上的“网络”选项卡):

operationName: "cancelOrder"
query: "mutation cancelOrder($id: ID!, $cancellationReasonId: ID!) {↵ cancelOrder(input: {id: $id, cancellationReasonId: $cancellationReasonId}) {↵ order {↵ id↵ isCancelled↵ __typename↵ }↵ __typename↵ }↵}↵"
variables: {id: "3045", cancellationReasonId: "1"}

编辑 2: 已经尝试像这样声明突变:

export const orderCancellation = gql`
mutation cancelOrder($input: CancelOrderInput!) {
cancelOrder(input: $input) {
order {
id,
isCancelled
}
}
}`;

this.apollo.mutate({
mutation: orderCancellation,
variables: {input: {id: orderId, cancellationReasonId: reasonId}}
});

最佳答案

我们找出问题所在。我们的服务器已将突变的 ID 声明为整数!,而不是 ID!。这是字符串 id 用于查询而不是突变的原因。感谢您的努力!

关于angular - Apollo + Angular 突变不适用于变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64685845/

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