Skip to content

Commit c90303b

Browse files
authored
Update graphql-provider.md
1 parent d4dae48 commit c90303b

File tree

1 file changed

+51
-50
lines changed

1 file changed

+51
-50
lines changed

src/content/code/language-support/java-kotlin-android/server/graphql-provider.md

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,74 +20,75 @@ github: babyfish-ct/graphql-provider
2020
> 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.
2121
2222
1. BookStoreMapper.kt
23-
```kt
24-
@Component
25-
class BookStoreMapper: EntityMapper<BookStore, UUID>() {
23+
```kt
24+
@Component
25+
class BookStoreMapper: EntityMapper<BookStore, UUID>() {
2626

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)
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+
}
3031
}
31-
}
32-
```
32+
```
3333

3434
2. BookMapper.kt
35-
```kt
36-
@Component
37-
class BookMapper: EntityMapper<Book, UUID>() {
35+
```kt
36+
@Component
37+
class BookMapper: EntityMapper<Book, UUID>() {
3838

39-
override fun EntityTypeDSL<Book, UUID>.config() {
39+
override fun EntityTypeDSL<Book, UUID>.config() {
4040

41-
reference(Book::store) // many-to-one
41+
reference(Book::store) // many-to-one
4242

43-
list(Book::authors) { // many-to-many
44-
db {
45-
middleTable {
46-
tableName = "BOOK_AUTHOR_MAPPING"
47-
joinColumnName = "BOOK_ID"
48-
targetJoinColumnName = "AUTHOR_ID"
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+
}
4950
}
5051
}
5152
}
5253
}
53-
}
54-
```
54+
```
5555

5656
3. Author.kt
57-
@Component
58-
class AuthorMapper: EntityMapper<Author, UUID>() {
57+
```kt
58+
@Component
59+
class AuthorMapper: EntityMapper<Author, UUID>() {
5960

60-
override fun EntityTypeDSL<Author, UUID>.config() {
61+
override fun EntityTypeDSL<Author, UUID>.config() {
6162

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)
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+
}
6567
}
66-
}
68+
```
6769

6870
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)
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+
fun findBooks(
78+
name: String?,
79+
storeName: String?
80+
): Connection<Book> =
81+
runtime.queryConnection {
82+
name?.let {
83+
db {
84+
where(table.name ilike it)
85+
}
8486
}
85-
}
86-
storeName?.let {
87-
db {
88-
where(table.store.name ilike it)
87+
storeName?.let {
88+
db {
89+
where(table.store.name ilike it)
90+
}
8991
}
9092
}
91-
}
92-
}
93-
```
93+
}
94+
```

0 commit comments

Comments
 (0)