Sunday, July 04, 2021

GraphQL Mutation Input

Without input type

  type Mutation {
    createCategory(name:String!):Category
    updateCategory(id:ID, name:String!):Category
    deleteCategory(id:ID):String

    createPublisher(name:String!):Publisher
    updatePublisher(id:ID, name:String!):Publisher
    deletePublisher(id:ID):String

    createAuthor(name:String!):Author
    updateAuthor(id:ID, firstName:String, lastName:String):Author
    deleteAuthor(id:ID):String

    createBook(title:String!, categoryId:String, publisherId:String, authorId:String):Book
    updateBook(id:ID, title:String!, categoryId:String, publisherId:String, authorId:String):Book
    deleteBook(id:ID):String
  }



With input type

  input CategoryInput {
    name:String!
  }
  input PublisherInput {
    name:String!
  }
  input AuthorInput {
    firstName:String
    lastName:String
  }
  input BookInput {
    title:String!
    categoryId:String
    publisherId:String
    authorId:String
  }
  type Mutation {
    createCategory(input:CategoryInput):Category
    updateCategory(id:ID, input:CategoryInput):Category
    deleteCategory(id:ID):String

    createPublisher(input:PubliserInput):Publisher
    updatePublisher(id:ID, input:PubliserInput):Publisher
    deletePublisher(id:ID):String

    createAuthor(input:AuthorInput):Author
    updateAuthor(id:ID, input:AuthorInput):Author
    deleteAuthor(id:ID):String
    
    createBook(input:BookInput):Book
    updateBook(id:ID, input:BookInput):Book
    deleteBook(id:ID):String
  }  



Correct the input foreign Key as type Int. They are categoryId, publisherId, authorId in BookInput.

 

  input BookInput {
    title:String!
    categoryId:Int
    publisherId:Int
    authorId:Int
  }

 



No comments: