How to make a mutation query for inserting a list of (Array) fields in GraphQL

后端 未结 2 628
夕颜
夕颜 2021-02-01 19:05

recently I started working on GraphQL, I am able to insert data in flat schema without any problem but when it comes to an Array of data I am getting an error like



        
2条回答
  •  -上瘾入骨i
    2021-02-01 19:34

    I ran into the same problem - I did not know how to specify array of objects in the input definition. So for those who wants to see a "text" schema solution:

    type Book {
      title: String!
    }
    

    to have an array of Books in your input type

    input AuthorInput {
      name: String!
      age: Int!
    }
    

    you can not just add books: [Book!] inside the input statement, you will need deliberately create input type containing needed fields (duplicate if you like):

    input BookInput {
      title: String!
    }
    

    and then you can:

    input AuthorInput {
      name: String!
      age: Int!
      books: [BookInput!]
    }
    

提交回复
热议问题