Skip to content

Commit a4158f4

Browse files
committed
Migrated to apollo data
1 parent 8f0f1f2 commit a4158f4

25 files changed

+487
-433
lines changed

.graphqlconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"schemaPath": "dev-tools/schema.graphql"
3+
}

dev-tools/graphql.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare module '*.graphql' {
2+
import { DocumentNode } from 'graphql'
3+
const Schema: DocumentNode
4+
5+
export = Schema
6+
}

dev-tools/schema.graphql

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
type Query {
2+
books(where: String!, order: String, limit: Int, offset: Int): BookResult!
3+
book(id: String!): Book
4+
}
5+
6+
type Mutation {
7+
changeStatus(id: ID!, status: Int!): Book!
8+
deleteBook(id: ID!, status: Int): Book!
9+
}
10+
11+
type Book {
12+
id: ID!
13+
title: String
14+
author: String
15+
status: Int
16+
progress: String
17+
size: Int
18+
LastAccess: Float
19+
LastModified: Float
20+
location: String
21+
startRead: Int
22+
endRead: Int
23+
readTime: Int
24+
lastRead: String
25+
thumbnail: String
26+
history: [BookHistory]
27+
}
28+
29+
type BookHistory {
30+
date: String!
31+
pages: Int!
32+
percent: Int
33+
progress: String
34+
speed: Int
35+
time: Int!
36+
}
37+
38+
type BookResult {
39+
total: Int!
40+
items: [Book]
41+
}

dev-tools/webpack/webpack.config.dev.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ exports.output = {
2323
}
2424

2525
exports.resolve = {
26-
extensions: ['.js', '.jsx', '.ts', '.tsx'],
26+
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx'],
2727
modules: ['src', 'node_modules'],
2828
}
2929

@@ -34,6 +34,10 @@ exports.module = {
3434
use: 'babel-loader',
3535
exclude: /node_modules/,
3636
},
37+
{
38+
test: /\.graphql$/i,
39+
use: 'raw-loader',
40+
},
3741
{
3842
test: /\.(png|woff|woff2|eot|ttf)$/,
3943
loader: 'url-loader',

dev-tools/webpack/webpack.config.prod.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const conf = {
2424
filename: '[name].js',
2525
},
2626
resolve: {
27-
extensions: ['.js', '.jsx', '.ts', '.tsx'],
27+
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx'],
2828
modules: ['src', 'node_modules'],
2929
alias: {
3030
react: 'preact/compat',
@@ -38,6 +38,10 @@ const conf = {
3838
use: [strip.loader('debug'), 'babel-loader'],
3939
exclude: /node_modules/,
4040
},
41+
{
42+
test: /\.graphql$/i,
43+
use: 'raw-loader',
44+
},
4145
{
4246
test: /\.(png|woff|woff2|eot|ttf)$/,
4347
loader: 'url-loader',

dev-tools/webpack/webpack.config.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ exports.output = {
3030
}
3131

3232
exports.resolve = {
33-
extensions: ['.js', '.jsx', '.ts', '.tsx'],
33+
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx'],
3434
modules: ['src', 'node_modules'],
3535
}
3636

@@ -41,6 +41,10 @@ exports.module = {
4141
use: [strip.loader('debug'), 'babel-loader'],
4242
exclude: /node_modules/,
4343
},
44+
{
45+
test: /\.graphql$/i,
46+
use: 'raw-loader',
47+
},
4448
{
4549
test: /\.(png|woff|woff2|eot|ttf)$/,
4650
loader: 'url-loader',

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
"test:open": "cypress open"
2323
},
2424
"dependencies": {
25+
"@apollo/react-hooks": "~3.1.3",
26+
"apollo-cache-inmemory": "~1.6.5",
27+
"apollo-client": "~2.6.8",
28+
"apollo-link-schema": "~1.2.4",
29+
"graphql": "^14.6.0",
30+
"graphql-tools": "~4.0.7",
2531
"hoist-non-react-statics": "~3.3.2",
2632
"jszip": "~3.2.2",
2733
"preact": "~10.3.4",
@@ -60,6 +66,7 @@
6066
"enzyme": "~3.11.0",
6167
"enzyme-adapter-react-16": "^1.15.2",
6268
"file-loader": "~6.0.0",
69+
"graphql-tag": "^2.10.3",
6370
"html-webpack-plugin": "~3.2.0",
6471
"husky": "^4.2.3",
6572
"identity-obj-proxy": "~3.0.0",
@@ -73,6 +80,7 @@
7380
"postcss-modules-values": "~3.0.0",
7481
"prettier": "^1.19.1",
7582
"pretty-quick": "^2.0.1",
83+
"raw-loader": "^4.0.0",
7684
"react-addons-test-utils": "~15.6.2",
7785
"react-test-renderer": "~16.13.1",
7886
"rimraf": "~3.0.2",

src/components/list-tab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ export default class ListTab extends React.Component<Props> {
4545
}
4646

4747
private renderRow(book: Book) {
48-
const { MD5, title, author } = book
48+
const { id, title, author } = book
4949
let thumbnail = book.thumbnail ? `/thumbnail/${book.thumbnail}` : null
5050

51-
return <ListItem thumbnail={thumbnail} center={title} subtitle={author} to={`/book/${MD5}`} key={MD5} />
51+
return <ListItem thumbnail={thumbnail} center={title} subtitle={author} to={`/book/${id}`} key={id} />
5252
}
5353
}

src/components/rsql.tsx

Lines changed: 0 additions & 135 deletions
This file was deleted.

src/components/style/list-tab.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
.spinner {
1010
margin-top: 14px;
11-
margin-bottom: 13px;
1211
text-align: center;
1312
width: 100%;
13+
height: 70px;
1414
}
1515

1616
@media (min-width: 960px) {

src/containers/App.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import * as React from 'react'
2+
import { ApolloProvider } from '@apollo/react-hooks'
3+
4+
import { client } from 'services/graphql'
25

36
import { Confirm } from 'components/confirm'
47
import { FileUploader } from 'components/uploader'
58
const s = require('theme/global.css')
69

710
export default function App({ children }) {
811
return (
9-
<div className={s.ios}>
10-
<Confirm>
11-
<FileUploader>{children}</FileUploader>
12-
</Confirm>
13-
</div>
12+
<ApolloProvider client={client}>
13+
<div className={s.ios}>
14+
<Confirm>
15+
<FileUploader>{children}</FileUploader>
16+
</Confirm>
17+
</div>
18+
</ApolloProvider>
1419
)
1520
}

src/models/book.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
export interface Book {
2-
MD5: string
2+
id: string
33
title: string
44
author: string
5-
lastRead: string
65
status: number
76
progress: string
87
size: number
@@ -13,6 +12,8 @@ export interface Book {
1312
endRead: number
1413
readTime: number
1514
thumbnail: string
15+
lastRead: string
16+
history: BookHistory[]
1617
}
1718

1819
export interface BookHistory {

src/models/rsql.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)