Spring Boot + GraphQL建立API的開源案例

banq發表於2018-12-10

這是用於處理作者/書籍資料的API,可以根據作者Id獲取者資訊和書籍資訊,資料庫:
作者:

CREATE TABLE `author` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(32) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `author_idx1` (`id`)
)


書籍表:

CREATE TABLE `book` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(32) NOT NULL,
  `author_id` bigint(20) NOT NULL,
  PRIMARY KEY (`id`),
  FOREIGN KEY (`author_id`) REFERENCES author(`id`),
  KEY `book_idx1` (`id`)
)


Schema定義:

type Author {
    id: ID!
    name: String!
    books: [Book]
}

type Book {
    id: ID!
    name: String!
}

type RegistAuthorResponse {
    name: String!,
    isRegist: Boolean!,
    errorMessage: String
}

type RegistBookResponse {
    authorId: ID!,
    name: String!,
    isRegist: Boolean!,
    errorMessage: String
}


解析器Resolver:
Resolver由GraphQL Java Tool提供。
 

相關文章