/
LaunchConnection.js
55 lines (50 loc) · 1.43 KB
/
LaunchConnection.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* This is a mst-sql generated file */
/* #region type-imports */
import { types } from "mobx-state-tree"
import { MSTGQLObject, MSTGQLRef } from "mst-gql"
import { RootStore } from "./index"
import { Launch } from "./Launch"
/* #endregion */
/* #region fragments */
export const launchConnectionPrimitives = `
__typename
cursor
hasMore
`
/* #endregion */
/* #region type-def */
/**
* LaunchConnection
*
* Simple wrapper around our list of launches that contains a cursor to the last item in the list. Pass this cursor to the launches query to fetch results after these.
*/
export const LaunchConnection = MSTGQLObject
.named('LaunchConnection')
.props({
__typename: types.optional(types.literal("LaunchConnection"), "LaunchConnection"),
cursor: types.string,
hasMore: types.boolean,
launches: types.array(MSTGQLRef(types.late(() => Launch))),
})
.views(self => ({
get store() {
return self.__getStore()
}
})) /* #endregion */
.volatile(self => ({
isFetchingMore: false
}))
.actions(self => ({
fetchMore() {
self.isFetchingMore = true
const query = self.store.fetchLaunches(self.cursor)
query.then(lc => self.doneFetchingMore(lc))
return query
},
doneFetchingMore(launchConnection) {
self.isFetchingMore = false
self.cursor = launchConnection.cursor
self.hasMore = launchConnection.hasMore
self.launches.push(...launchConnection.launches)
}
}))