![](/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.