-
Notifications
You must be signed in to change notification settings - Fork 7
Conversation
} from '../../../graphql/generated/TimetableRowFragment'; | ||
|
||
export const TIMETABLE_ROW_FRAGMENT = gql` | ||
fragment TimetableRowFragment on SessionConnection { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここで on Query
として sessionList { ... }
としなかったのは、取得件数の指定が上位Componentの責務であると考えたため。
そうすると、このComponentの責任範囲としては sessionList の返り値である SessionConnection に対する要求から書き始めるのが正しいはず。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
細かいですがConnectionはページングの責務も含んでるんで、このRowに対しては Session
そのものが責務として合ってるのかなと思いました
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
わかる。しかしsessionListをフィルタして妥当なデータを見つける処理がここに入っている構造上仕方ないのだ…(その構造が悪いのでリファクタリングしたほうがよさはある
|
||
export const TIMETABLE_SECTION_FRAGMENT = gql` | ||
fragment TimetableSectionFragment on Query { | ||
sessionList { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここで件数を指定したりできます。
将来的に ContentGrid
と件数がズレた場合、aliasを設定する必要があるかも(めんどいね
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これはQueryの関数(?)自体をFragmentにしてるときに起きるケースとして面白いですね!!
今はいい考えが湧いてこないけどこういうことも起こるんだなぁなるほどなるほど
@@ -9,7 +9,7 @@ | |||
"lint": "tslint -c tslint.json -p tsconfig.json", | |||
"lint:fix": "npm run lint -- --fix", | |||
"precommit": "lint-staged", | |||
"codegen": "apollo codegen:generate graphql/generated --schema ../schema.graphql --addTypename --target typescript --outputFlat" | |||
"codegen": "rm -rf graphql/generated && apollo codegen:generate graphql/generated --schema ../schema.graphql --addTypename --target typescript --outputFlat" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm -rf しておかないと、消したFragmentやらのファイルが残ってて意図せずコンパイルが通ってしまう場合があったので型定義を生成するたびに一回消すようにしました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
めっちゃ勉強なりました 🙇 🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
知見が得られるコードレビューで面白かったです 😂
<NewsSection data={data} /> | ||
<AboutSection /> | ||
<ContentSection data={data} /> | ||
<StyledTimetableSection data={data} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここはdataがまるごと渡ってて違和感あるような。
でも子コンポーネントのPropsを見ると自分のFragmentになってて型としてはOKってことなんすね〜。
graphql-anywhereのfilterはこういうときに使うのかな?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
まぁまぁわかる
|
||
const NewsSection: React.SFC = ({ ...props }) => ( | ||
interface Props { | ||
data: NewsListFragment; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 一瞬ん?ってなったのはこれがバケツリレーしてるだけのコンポーネントだからか。。なるほどなるほど
} | ||
`; | ||
|
||
const NewsList: React.SFC<Props> = ({ ...props }) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: ({ data, ...props })
もしくは ({ data: { newsList }, ...props })
すればよいかも
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
まかせた!(なげやり
} from '../../../graphql/generated/TimetableRowFragment'; | ||
|
||
export const TIMETABLE_ROW_FRAGMENT = gql` | ||
fragment TimetableRowFragment on SessionConnection { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
細かいですがConnectionはページングの責務も含んでるんで、このRowに対しては Session
そのものが責務として合ってるのかなと思いました
|
||
export const TIMETABLE_SECTION_FRAGMENT = gql` | ||
fragment TimetableSectionFragment on Query { | ||
sessionList { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これはQueryの関数(?)自体をFragmentにしてるときに起きるケースとして面白いですね!!
今はいい考えが湧いてこないけどこういうことも起こるんだなぁなるほどなるほど
これはFragmentを使う上でやらないとデータが子に渡らないのでルールと言うか必須なのでは? 🤔
ContentSectionでいうと、現状のComponent分割構成を見直すべきなのかも?と思った。 <Section title="NEWS" id="news">
<News data={filter(NewsFragment, data))} />
</Section>
<Section title="ABOUT" id="about">
<About />
</Section>
<Section title="CONTENTS" id="contents">
<Contents data={filter(ContentsFragment, data)} />
</Section>
<Section title="TIME TABLE" id="time_table">
<TimeTable data={filter(TimeTableFragment, data)} />
</Section> こうなってるとか。孫Fragment問題はやらない案に同意です。 |
次のルールがあったほうがよさそうだなーと思ったので、それに沿って直してみている。
pages/
配下のComponentのみ(自分を使うComponent名)Fragment
とするTimetableRowFragment
が参考になるかも判断に悩む 🤔
ContentSection
はTop
とContentGrid
を繋いでいるが、ContentSectionFragmentを定義するべきか?