I had a problem with Spring for GraphQL, I was trying to add a book to an existing static list of book using mutation. How to achieve it ?
If my schema is,
type Mutation {
addBook(book: Book): Book
}
type Book {
id: ID!
name: String!
author: Author
}
type Author {
id: ID!
fname: String!
lname: String
}
and I try to do at the java layer as,
@MutationMapping
public Book addBook(Book book) {
Book.addBook(book);
}
I am getting error stating that Book is not input param (Consider Book is a record type having a static list and add method). Now to fix it when I am adding another BookInput input type in schema,
input BookInput {
id: ID!
name: String!
author: Author
}
it is saying Author is not an input type. Now if I go ahead with another AuthorInput in my schema how will it resolve that correlation (do I need to write another SchemaMapping for the BookInput type and author field). Also isn't this a lot of redundant coding ? I am sure there is a way to avoid all of it. Please advise.