|
1 | 1 | ---
|
2 | 2 | name: graphql-provider
|
3 |
| -description: GraphQL server-side rapid development framework, if users use RDBMS to manage persistent data, it can help users to quickly build GraphQL services in the shortest time (based on kotlin and R2DBC) |
| 3 | +description: GraphQL server-side rapid development framework, it's GRM(GraphQL relation Mapping), if users use RDBMS to manage persistent data, it can help users to quickly build GraphQL services in the shortest time (based on kotlin and R2DBC) |
4 | 4 | url: https://github.com/babyfish-ct/graphql-provider
|
5 | 5 | github: babyfish-ct/graphql-provider
|
6 | 6 | ---
|
7 | 7 |
|
8 | 8 | 1. It is a GRM (GraphQL-Relation mapping), and its usage is similar to ORM. When kotlin dsl is used to complete the mapping configuration between entities and tables, GraphQL objects and associations are automatically completed, including the runtime association-level DataLoader and related batch loading optimization.
|
9 | 9 |
|
10 |
| -2. It is easy to add user implemention fields to entity, where you can implement business-related calculations. User implementation fields can also enjoy the automatic generated DataLoader and related batch query optimization at runtime. |
| 10 | +2. It is easy to add user implemention fields to entity, where you can implement business-related calculations. User implementation fields can also enjoy the automatic generated DataLoader and related batch loading optimization at runtime. |
11 | 11 |
|
12 | 12 | 3. Whether it is to implement query-level arguments or association-level arguments, you only need to use strongly typed SQL DSL to specify some dynamic filtering and sorting, and the rest is done automatically.
|
13 | 13 |
|
14 | 14 | 4. If you need pagination query, there is no development cost except changing the return type of ordinary query from List<T> to Connection<T>.
|
15 | 15 |
|
16 |
| -5. For mutation operations, the inputs type can be automatically generated according to a simple configuration, only need to focus on entity objects, not input objects. At runtime, the framework can automatically convert the input object to a dynamic entity object tree and you only need one sentence to save any complex entity object tree to the database. |
| 16 | +5. For mutation operations, the inputs type can be automatically generated according to a simple configuration, develpers only need to focus on entity objects, not input objects. At runtime, the framework can automatically convert the input object to a dynamic entity object tree and you only need one sentence to save any complex entity object tree to the database. |
17 | 17 |
|
| 18 | +* Here is a simple example* |
18 | 19 |
|
| 20 | +> Due to space limitations, all EntityMapper only uses a static mapping configuration similar to ORM, and does not use a more dynamic code configuration. For a complete demonstration, please refer to the example and documentation of the project itself. |
| 21 | +
|
| 22 | +1. BookStoreMapper.kt |
| 23 | +```kt |
| 24 | +@Component |
| 25 | +class BookStoreMapper: EntityMapper<BookStore, UUID>() { |
| 26 | + |
| 27 | + // Inverse one-to-many "BookStore.books" is the the |
| 28 | + // mirror image of many-to-one association "Book.store" |
| 29 | + mappedList(BookStore::books, Book::store) |
| 30 | + } |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +2. BookMapper.kt |
| 35 | +```kt |
| 36 | +@Component |
| 37 | +class BookMapper: EntityMapper<Book, UUID>() { |
| 38 | + |
| 39 | + override fun EntityTypeDSL<Book, UUID>.config() { |
| 40 | + |
| 41 | + reference(Book::store) // many-to-one |
| 42 | + |
| 43 | + list(Book::authors) { // many-to-many |
| 44 | + db { |
| 45 | + middleTable { |
| 46 | + tableName = "BOOK_AUTHOR_MAPPING" |
| 47 | + joinColumnName = "BOOK_ID" |
| 48 | + targetJoinColumnName = "AUTHOR_ID" |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +3. Author.kt |
| 57 | +@Component |
| 58 | +class AuthorMapper: EntityMapper<Author, UUID>() { |
| 59 | + |
| 60 | + override fun EntityTypeDSL<Author, UUID>.config() { |
| 61 | + |
| 62 | + // Inverse many-to-many "Author.books" is the the |
| 63 | + // mirror image of many-to-many association "Book.authors" |
| 64 | + mappedList(Author::books, Book::authors) |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +4. BookQuery.kt |
| 69 | + |
| 70 | +```kt |
| 71 | +@Service |
| 72 | +class BookQuery: Query() { |
| 73 | + |
| 74 | + // Return type is Connection<Book>, not List<Book>, |
| 75 | + // that means its pagination query. |
| 76 | + fun findBooks( |
| 77 | + name: String?, |
| 78 | + storeName: String? |
| 79 | + ): Connection<Book> = |
| 80 | + runtime.queryConnection { |
| 81 | + name?.let { |
| 82 | + db { |
| 83 | + where(table.name ilike it) |
| 84 | + } |
| 85 | + } |
| 86 | + storeName?.let { |
| 87 | + db { |
| 88 | + where(table.store.name ilike it) |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | +} |
| 93 | +``` |
0 commit comments