zao
09/28/2020, 4:13 AM아래의 query를 다음과 같은 조건으로 가공하고싶습니다.
# 1. status가 true (!isDog 일때는, dogTypes의 status로 필터링)
# 2. isDog 일때, dogTypes 으로 필터링
# 3. !isDog 일때, catTypes, catInfo로 필터링
# 4. isSent가 false
# 5. [number]를 조회하면서, 각각에대해 외부 api를 연동해서 결과가 true
# 6. 5번이 true이였을 시점의 시간으로부터 하루 이내
query Pets {
pets {
id
isDog
status
catTypes {
id
isSent
}
catInfo {
id
number
}
dogTypes {
status
dogInfo {
isSent
number
}
}
}
}
Hyeseong Kim
09/28/2020, 4:16 AMzao
09/28/2020, 4:42 AMHyeseong Kim
09/28/2020, 5:31 AMinterface PetInfo
type DogInfo implements PetInfo
type CatInfo implements PetInfo
만 하셔도 쿼리는
query Pets {
pets(filter: { state: { ... } }) {
id
...on DogInfo {
# ...
}
...on CatInfo {
# ...
}
}
}
이런식으로 더 깔끔하게 갈라질겁니다.Hyeseong Kim
09/28/2020, 5:32 AMProduct‐centric: GraphQL is unapologetically driven by the requirements of views and the front‐end engineers that write them. GraphQL starts with their way of thinking and requirements and builds the language and runtime necessary to enable that.
Client‐specified queries: Through its type system, a GraphQL server publishes the capabilities that its clients are allowed to consume. It is the client that is responsible for specifying exactly how it will consume those published capabilities. These queries are specified at field‐level granularity. In the majority of client‐server applications written without GraphQL, the server determines the data returned in its various scripted endpoints. A GraphQL query, on the other hand, returns exactly what a client asks for and no more.https://spec.graphql.org/June2018/#sec-Overview 이건 GraphQL 스펙에 명시되어있는 설계 원칙입니다.
백엔드팀에게 개선요청했으나, graphql은 필요한 데이터만 뽑아쓰고, 필터링 할 수 있기때문에 프론트에서 가공하는게 맞다.이런 사고방식은 전반적으로 케이스 스터디 등 학습과정을 통해 개선할 필요가 있을거에요
zao
09/28/2020, 5:36 AMHyeseong Kim
09/28/2020, 5:37 AMHyeseong Kim
09/28/2020, 5:44 AMzao
09/28/2020, 5:59 AM