Skip to content

Commit b0ae9d0

Browse files
authored
Merge pull request #1220 from babyfish-ct/source
Add src/content/code/language-support/java-kotlin-androd/server/graph…
2 parents b5ae6a1 + 9971450 commit b0ae9d0

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
name: graphql-provider
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+
url: https://github.com/babyfish-ct/graphql-provider
5+
github: babyfish-ct/graphql-provider
6+
---
7+
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+
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+
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+
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+
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+
18+
**Here is a simple example**
19+
20+
> Due to space limitations, all *EntityMapper*s 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+
```kt
58+
@Component
59+
class AuthorMapper: EntityMapper<Author, UUID>() {
60+
61+
override fun EntityTypeDSL<Author, UUID>.config() {
62+
63+
// Inverse many-to-many "Author.books" is the the
64+
// mirror image of many-to-many association "Book.authors"
65+
mappedList(Author::books, Book::authors)
66+
}
67+
}
68+
```
69+
70+
4. BookQuery.kt
71+
```kt
72+
@Service
73+
class BookQuery: Query() {
74+
75+
// Return type is Connection<Book>, not List<Book>,
76+
// that means its pagination query.
77+
// pagination arguments such as "first", "after", "last", "before"
78+
// will be added by framework automactically and implicitly
79+
fun findBooks(
80+
name: String?,
81+
storeName: String?
82+
): Connection<Book> =
83+
runtime.queryConnection {
84+
name?.let {
85+
db {
86+
where(table.name ilike it)
87+
}
88+
}
89+
storeName?.let {
90+
db {
91+
where(table.store.name ilike it)
92+
}
93+
}
94+
}
95+
}
96+
```

0 commit comments

Comments
 (0)