![](/img/trans.png)
[英]How to resolve missing artifact error when using Eclipse AWS plugin?
[英]How to resolve validation error when querying with graphql? (typescript)
我试图通过传入name
字段进行查询,但出现两个不同的错误。
"Validation error of type MissingFieldArgument:
Missing field argument id @ 'getBlog'"
"Validation error of type UnknownArgument:
Unknown field argument name @ 'getBlog'"
我能够使用id
字段成功查询它。 我是 graphql 的新手,我在我的应用程序上使用它,它也使用 aws amplify 和 aws appsync。
schema.graphql
type Blog @model {
id: ID!
name: String!
posts: [Post] @connection(keyName: "byBlog", fields: ["id"])
}
queries.ts
// this is an auto generated file. This will be overwritten
export const getBlog = /* GraphQL */ `
query GetBlog($name: String!) { //changed from ($id: ID!)
getBlog(name: $name) { //changed from (id: $id)
id
name
posts {
items {
id
title
blogID
createdAt
updatedAt
}
nextToken
}
createdAt
updatedAt
}
}
`;
app.tsx
const getRecord = async () => {
const result = await API.graphql(graphqlOperation(getBlog, {name: "testing"}))
console.log(result)
}
我也尝试将其推送到 aws amplify push
但未检测到任何变化。 我没想到会这样,因为我没有更改架构中的任何内容,只有查询。 提前致谢
如果您查看 GraphQL架构,您应该会看到GetBlog
查询的定义。 它可能看起来像:
query {
GetBlog(id: ID!): Blog
}
该特定查询只能由id
查询。 假设您可以控制服务器,您还应该能够定义GetBlogByName
查询:
query {
GetBlogByName(name: String): Blog
}
但是接下来由您来确保name
是唯一的或处理可能 >1 的响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.