Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
779 views
in Technique[技术] by (71.8m points)

reactjs - ID cannot represent a non-string and non-integer value

Here is the thing, I'm building a simple inventory app that has products and parts. Products can have many parts and part can be in many Products.

I'm using React and GraphQL with Strapi backend and I want to update a product to add or remove certain products.

I can't go pass this error in GraphQL playground:

ID cannot represent a non-string and non-integer value:

I've tried with id: 1, id: "1", id: 1, id: "1" nothing works. Here is the Docs for the input:

enter image description here

I'm trying like this but it doesn't work:

mutation {
  updateProduct (input:{
    where:{
      id: 2
    }
    data: {
      parts: [
        {
          id: 3
        }
      ]
    }
  }){
    product{
      id
      productName
      parts {
        id
        partName
      }
    }
  }
}

I'd appreciate any help,

Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Finally figured it out, turns out docs said it all along. It said: parts[ID] so I only had to:

mutation {
  updateProduct (input:{
    where:{
      id: 2
    }
    data: {
      parts: [
        3
      ]
    }
...

or if I wanted multiple parts I had to add it:

...
    data: {
      parts: [
         3,2
      ]
    }
...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...