티스토리 뷰
React Graphql Masterclass
32. Data Resolver - Overriding A Field
GraphQL 서버는 graphql 요청시 scalar 타입이면 값을 그대로 response하고 object 타입이면 object 타입의 각 필드마다 관련된 매핑 함수가 있는지 확인한다.
예를 들어 아래와 같은 데이터 구조에서
type Query {
sayHello: String
customers: [Customer]!
}
type Customer {
id: ID
name: String
age: Int
city: String
}
public class Customer {
private Integer id;
private String name;
private Integer age;
private String city;;
}
쿼리 요청시에 sayHello 필드는 string을 바로 내려주지만, Customer 필드를 확인할 때 해당 필드는 Object 타입이므로 각 필드가 scalar를 리턴해도 관련 매핑 함수가 있는지 확인한 뒤 실행한 값을 내려준다.
아래와 같은 age관련 함수가 있다면 항상 100을 내려줄 것이다.
@SchemaMapping(typeName = "Customer")
public Mono<Integer> age() {
return Mono.just(100);
}
'Study > TIL (Today I Learned)' 카테고리의 다른 글
20220917 TIL (0) | 2022.09.17 |
---|---|
20220831 TIL (0) | 2022.08.31 |
20220830 TIL (0) | 2022.08.30 |
20220726 TIL (0) | 2022.07.26 |
20220724 TIL (0) | 2022.07.24 |
댓글
최근에 올라온 글
최근에 달린 댓글
TAG
- 생활코딩리눅스
- 20200424
- 20200428
- 20201204
- 20200429
- 20200622
- 20200420
- 20200503
- 20200403
- chapter7
- 20200425
- 20200510
- 백준
- 20200319
- chapter8
- 20200421
- 20200624
- 20200423
- 20200804
- 20200512
- 20200427
- 20200415
- 20200504
- 20200330
- likelion
- 20200406
- 20200502
- 20200417
- 20200413
- 20200317
- Total
- Today
- Yesterday