gpt4 book ai didi

Error: @default only accepts scalar types, which might be why the array lints badly(ERROR:@DEFAULT只接受标量类型,这可能是数组链接错误的原因)

转载 作者:bug小助手 更新时间:2023-10-24 17:54:29 31 4
gpt4 key购买 nike



I'm trying to amplify push my updated amplify/backend/api/<myAPIName>/schema.graphql file. I am getting the following error:

我正在尝试扩大推送我更新的amplify/backend/api/ /schema.graphql文件。我收到以下错误:


An error occurred during the push operation: /
Schema validation failed.

Expected type String, found ["Admins", "Users"].

canRead: [String] @default(value: ["Admins", "Users"])

Expected type String, found ["Admins", "Users"].

The offending code in schema.graphql:

Schema.graph ql中有问题的代码:


type Card {
...
canRead: [String] @default(value: ["Admins", "Users"])
}

As you can see, I'm trying to set a field "canRead" on my Card object. The field should be an array of strings. I want the default value to be ["Admins", "Users"], but Amplify/graphql only accepts Scalar types for default values.

如您所见,我正在尝试在我的Card对象上设置一个字段“canRead”。该字段应为字符串数组。我希望缺省值为[“admins”,“user”],但Amplify/GraphQL只接受Scalar类型作为缺省值。


The GraphQL documentation lists things such as integers and strings as Scalar types, but then confusingly says that "appearsIn" will resolve to a scalar in the provided example:

GraphQL文档将整数和字符串之类的内容作为Scalar类型列出,但在所提供的示例中却令人困惑地说“outarsIn”将解析为标量:



{
"data": {
"hero": {
"name": "R2-D2",
"appearsIn": [
"NEWHOPE",
"EMPIRE",
"JEDI"
]
}
}


Which I took to mean that an array of strings might also be considered a scalar, but apparently not or else my code would presumably work?

我认为这意味着字符串数组也可以被视为标量,但显然不是,否则我的代码可能会工作?


The documentation goes on to tease with the following:

该文档接着对以下内容进行了调侃:



In most GraphQL service implementations, there is also a way to
specify custom scalar types. For example, we could define a Date type:


scalar Date


Then it's up to our implementation to define how
that type should be serialized, deserialized, and validated. For
example, you could specify that the Date type should always be
serialized into an integer timestamp, and your client should know to
expect that format for any date fields.



But it doesn't describe how to do this, and what the limitations are. Can anyone advise if/how defining a default array of strings can be achieved?

但它没有描述如何做到这一点,以及限制是什么。有人能告诉我是否/如何定义默认字符串数组吗?


更多回答
优秀答案推荐

Had something similar come up recently also.

最近也有类似的事情发生。


I don't think you can specify a default for an Array, only scalar types as mentioned in the docs here: https://docs.amplify.aws/cli/graphql/data-modeling/#assign-default-values-for-fields I think the tease "and more" refers to the AWS specific types referenced here: https://docs.aws.amazon.com/appsync/latest/devguide/scalars.html which covers off ID, Int, String, Float, Boolean and some exotic types from AWS like AWSDateTime

我不认为您可以为数组指定缺省类型,只能指定此处文档中提到的标量类型:https://docs.amplify.aws/cli/graphql/data-modeling/#assign-default-values-for-fields我认为“和更多”一词指的是这里引用的AWS特定类型:https://docs.aws.amazon.com/appsync/latest/devguide/scalars.html,它涵盖了ID、Int、字符串、浮点数、布尔值和AWSDateTime等AWSDateTime等AWS中的特殊类型


My option was to set on creation - Not the answer you're looking for but hope it helps.

我的选择是开始创作--这不是你想要的答案,但希望它能有所帮助。


更多回答

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