Skip to content

Commit 1fcc444

Browse files
committed
Merge branch 'source' of https://github.com/babyfish-ct/graphql.github.io into source
2 parents b0e952e + bcebf4b commit 1fcc444

File tree

1 file changed

+85
-3
lines changed

1 file changed

+85
-3
lines changed
Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,100 @@
11
---
22
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)
44
url: https://github.com/babyfish-ct/graphql-provider
55
github: babyfish-ct/graphql-provider
66
---
77

8+
Video: https://www.youtube.com/watch?v=5UxmkNbCe0Q
9+
810
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.
911

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.
12+
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.
1113

1214
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.
1315

1416
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>.
1517

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.
18+
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.
19+
20+
6. Integrated Spring security and JWT. Allows users to authorize by behavior, authorize by column, and authorize by row through the kotlin DSL.
21+
22+
**Here is a simple example**
23+
24+
> 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.
25+
26+
1. BookStoreMapper.kt
27+
```kt
28+
@Component
29+
class BookStoreMapper: EntityMapper<BookStore, UUID>() {
30+
31+
// Inverse one-to-many "BookStore.books" is the the
32+
// mirror image of many-to-one association "Book.store"
33+
mappedList(BookStore::books, Book::store)
34+
}
35+
}
36+
```
37+
38+
2. BookMapper.kt
39+
```kt
40+
@Component
41+
class BookMapper: EntityMapper<Book, UUID>() {
42+
43+
override fun EntityTypeDSL<Book, UUID>.config() {
44+
45+
reference(Book::store) // many-to-one
46+
47+
list(Book::authors) { // many-to-many
48+
db {
49+
middleTable {
50+
tableName = "BOOK_AUTHOR_MAPPING"
51+
joinColumnName = "BOOK_ID"
52+
targetJoinColumnName = "AUTHOR_ID"
53+
}
54+
}
55+
}
56+
}
57+
}
58+
```
59+
60+
3. Author.kt
61+
```kt
62+
@Component
63+
class AuthorMapper: EntityMapper<Author, UUID>() {
64+
65+
override fun EntityTypeDSL<Author, UUID>.config() {
66+
67+
// Inverse many-to-many "Author.books" is the the
68+
// mirror image of many-to-many association "Book.authors"
69+
mappedList(Author::books, Book::authors)
70+
}
71+
}
72+
```
1773

74+
4. BookQuery.kt
75+
```kt
76+
@Service
77+
class BookQuery: Query() {
1878

79+
// Return type is Connection<Book>, not List<Book>,
80+
// that means its pagination query.
81+
// pagination arguments such as "first", "after", "last", "before"
82+
// will be added by framework automactically and implicitly
83+
suspend fun findBooks(
84+
name: String?,
85+
storeName: String?
86+
): Connection<Book> =
87+
runtime.queryConnection {
88+
name?.let {
89+
db {
90+
where(table.name ilike it)
91+
}
92+
}
93+
storeName?.let {
94+
db {
95+
where(table.store.name ilike it)
96+
}
97+
}
98+
}
99+
}
100+
```

0 commit comments

Comments
 (0)