Reactjs 使用AWS amplify数据存储和GraphQL创建变异时出错:“0”;变量';输入';已强制非Null类型为Null值';身份证'&引用;

Reactjs 使用AWS amplify数据存储和GraphQL创建变异时出错:“0”;变量';输入';已强制非Null类型为Null值';身份证'&引用;,reactjs,graphql,aws-amplify,aws-appsync,Reactjs,Graphql,Aws Amplify,Aws Appsync,我试图用aws amplify数据存储创建一个web应用程序,在这里创建博客、帖子和评论,当我试图在博客中发布帖子时,我得到一个错误,amplify抛出的答案是“blogID”字段为空,而实际上,如果我用ID发送它 我已经试着遵循我看到的其他帖子的说明,我正在遵循amplify中的数据存储文档,我只是不知道发生了什么,我认为这与模式有着严重的关系,奇怪的是模式是这样的,amplify CLI配置是如何给我的 只有当我尝试向相关的模型发出请求时(在本例中为插入)才会发生这种情况 这是我发送到数据存

我试图用aws amplify数据存储创建一个web应用程序,在这里创建博客、帖子和评论,当我试图在博客中发布帖子时,我得到一个错误,amplify抛出的答案是“blogID”字段为空,而实际上,如果我用ID发送它

我已经试着遵循我看到的其他帖子的说明,我正在遵循amplify中的数据存储文档,我只是不知道发生了什么,我认为这与模式有着严重的关系,奇怪的是模式是这样的,amplify CLI配置是如何给我的

只有当我尝试向相关的模型发出请求时(在本例中为插入)才会发生这种情况

这是我发送到数据存储的内容

{title: "new post", blogID: "3e1fdd25-4f63-4d68-ac0b-f84d95ff4951"}
这给了我放大的反应

{title: "new post", blogID: null, id: "6d5efbe0-ea36-41c8-84ce-b4194d7fee30", _version: undefined, _lastChangedAt: undefined, …}
它说我将BlogID作为null发送,但事实并非如此,它向我抛出以下消息:“变量'input'强制非null类型'ID!'为null值!”

这是我的模式。graphql

type Blog @model {
  id: ID!
  name: String!
  posts: [Post] @connection(keyName: "byBlog", fields: ["id"])
}

type Post @model @key(name: "byBlog", fields: ["blogID"]) {
  id: ID!
  title: String!
  blogID: ID!
  blog: Blog @connection(fields: ["blogID"])
  comments: [Comment] @connection(keyName: "byPost", fields: ["id"])
}

type Comment @model @key(name: "byPost", fields: ["postID", "content"]) {
  id: ID!
  postID: ID!
  post: Post @connection(fields: ["postID"])
  content: String!
}
这是突变

export const createPost = /* GraphQL */ `
  mutation CreatePost(
    $input: CreatePostInput!
    $condition: ModelPostConditionInput
  ) {
    createPost(input: $input, condition: $condition) {
      id
      title
      blogID
      blog {
        id
        name
        posts {
          nextToken
          startedAt
        }
        _version
        _deleted
        _lastChangedAt
        createdAt
        updatedAt
      }
      comments {
        items {
          id
          postID
          content
          _version
          _deleted
          _lastChangedAt
          createdAt
          updatedAt
        }
        nextToken
        startedAt
      }
      _version
      _deleted
      _lastChangedAt
      createdAt
      updatedAt
    }
  }
`;
这是我创建帖子的代码

const handleAddPost = async () => {
        try {
            await DataStore.save(new Post({
                title: title,
                blogID: blog.id,
            }))
            .then(res => console.log(res))
            .catch(err => console.log(err));
        } catch (error) {
            console.log(error);
        }
        setTitle('');
    }

我看到这里有一些关于相同问题的帖子,但没有一篇对我有效,我想相信这是graphQL模式的关系模型,我希望你能帮助我

证明你发送了正确的数据-显示
console.log(title,blog.id)的结果我在函数handleAddPost:console.log(title,blog.id)中打印它;并返回给我这个:新帖子c63a337b-b76a-467b-9f3a-f186abde08f1,我检查了它是否是正确的ID