Skip to content

Commit 97276dd

Browse files
committed
新增 mutaion
1 parent fe8ad5e commit 97276dd

29 files changed

+4573
-542
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
BSD License
2+
3+
For Relay Starter Kit software
4+
5+
Copyright (c) 2013-2015, Facebook, Inc.
6+
All rights reserved.
7+
8+
Redistribution and use in source and binary forms, with or without modification,
9+
are permitted provided that the following conditions are met:
10+
11+
* Redistributions of source code must retain the above copyright notice, this
12+
list of conditions and the following disclaimer.
13+
14+
* Redistributions in binary form must reproduce the above copyright notice,
15+
this list of conditions and the following disclaimer in the documentation
16+
and/or other materials provided with the distribution.
17+
18+
* Neither the name Facebook nor the names of its contributors may be used to
19+
endorse or promote products derived from this software without specific
20+
prior written permission.
21+
22+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Additional Grant of Patent Rights Version 2
2+
3+
"Software" means the Relay Starter Kit software distributed by Facebook, Inc.
4+
5+
Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software
6+
("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable
7+
(subject to the termination provision below) license under any Necessary
8+
Claims, to make, have made, use, sell, offer to sell, import, and otherwise
9+
transfer the Software. For avoidance of doubt, no license is granted under
10+
Facebook's rights in any patent claims that are infringed by (i) modifications
11+
to the Software made by you or any third party or (ii) the Software in
12+
combination with any software or other technology.
13+
14+
The license granted hereunder will terminate, automatically and without notice,
15+
if you (or any of your subsidiaries, corporate affiliates or agents) initiate
16+
directly or indirectly, or take a direct financial interest in, any Patent
17+
Assertion: (i) against Facebook or any of its subsidiaries or corporate
18+
affiliates, (ii) against any party if such Patent Assertion arises in whole or
19+
in part from any software, technology, product or service of Facebook or any of
20+
its subsidiaries or corporate affiliates, or (iii) against any party relating
21+
to the Software. Notwithstanding the foregoing, if Facebook or any of its
22+
subsidiaries or corporate affiliates files a lawsuit alleging patent
23+
infringement against you in the first instance, and you respond by filing a
24+
patent infringement counterclaim in that lawsuit against that party that is
25+
unrelated to the Software, the license granted hereunder will not terminate
26+
under section (i) of this paragraph due to such counterclaim.
27+
28+
A "Necessary Claim" is a claim of a patent owned by Facebook that is
29+
necessarily infringed by the Software standing alone.
30+
31+
A "Patent Assertion" is any lawsuit or other action alleging direct, indirect,
32+
or contributory infringement or inducement to infringe any patent, including a
33+
cross-claim or counterclaim.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Relay Starter Kit
2+
3+
This kit includes an app server, a GraphQL server, and a transpiler that you can use to get started building an app with Relay. For a walkthrough, see the [Relay tutorial](https://facebook.github.io/relay/docs/tutorial.html).
4+
5+
## Installation
6+
7+
```
8+
npm install
9+
```
10+
11+
## Running
12+
13+
Start a local server:
14+
15+
```
16+
npm start
17+
```
18+
19+
## Developing
20+
21+
Any changes you make to files in the `js/` directory will cause the server to
22+
automatically rebuild the app and refresh your browser.
23+
24+
If at any time you make changes to `data/schema.js`, stop the server,
25+
regenerate `data/schema.json`, and restart the server:
26+
27+
```
28+
npm run update-schema
29+
npm start
30+
```
31+
32+
## License
33+
34+
Relay Starter Kit is [BSD licensed](./LICENSE). We also provide an additional [patent grant](./PATENTS).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var getbabelRelayPlugin = require('babel-relay-plugin');
2+
var schema = require('../data/schema.json');
3+
4+
module.exports = getbabelRelayPlugin(schema.data);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/**
2+
* Created by simon on 2017/3/10.
3+
*/
4+
5+
// client side 暂存 store,GraphQL Server reponse 会更新 store,再透过 props 传递给 Component
6+
const STORE = {};
7+
8+
// 中国十大名茶
9+
// 碧螺春、
10+
// 西湖龙井、
11+
// 安徽毛峰、
12+
// 安徽瓜片、
13+
// 恩施玉露、
14+
// 福建铁观音、
15+
// 福建银针、
16+
// 云南普洱茶、
17+
// 福建云茶、
18+
// 江西云雾茶
19+
20+
// 日本三大名茶 [PS: 光听名字就不好喝]
21+
// 宇治茶(京都府)、
22+
// 狭山茶(崎玉县)、
23+
// 静冈茶(静冈县)
24+
const teas = [
25+
{ name: '碧螺春', id: 1 },
26+
{ name: '西湖龙井', id: 2 },
27+
{ name: '安徽毛峰', id: 3 },
28+
{ name: '安徽瓜片', id: 4 },
29+
{ name: '恩施玉露', id: 5 },
30+
{ name: '福建铁观音', id: 6 },
31+
{ name: '福建银针', id: 7 },
32+
{ name: '云南普洱茶', id: 8 },
33+
{ name: '福建云茶', id: 9 },
34+
{ name: '江西云雾茶', id: 10 },
35+
{ name: '宇治茶', id: 11 },
36+
{ name: '狭山茶', id: 12 },
37+
{ name: '静冈茶', id: 13 },
38+
]
39+
40+
const chineseTea = {
41+
id: 1,
42+
name: 'China',
43+
teaIds: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
44+
}
45+
46+
const japaneseTea = {
47+
id: 10086,
48+
name: 'japan',
49+
teaIds: [11, 12, 13]
50+
}
51+
52+
const data = {
53+
contries: [
54+
chineseTea,
55+
japaneseTea
56+
],
57+
58+
teas: teas
59+
}
60+
61+
/**
62+
* 获取所有国家
63+
* @returns {Array}
64+
*/
65+
export function getContries(names) {
66+
return names.map(name => {
67+
if (name === 'China') {
68+
return data.contries[0];
69+
}
70+
if (name === 'japan') {
71+
return data.contries[1];
72+
}
73+
return null;
74+
});
75+
}
76+
77+
export function getContry(id) {
78+
return data.contries.find(c => c.id === id)
79+
}
80+
81+
export function getContryByName(name) {
82+
console.info(name)
83+
return data.contries.filter(contry => contry.name === name)[0]
84+
}
85+
86+
/**
87+
* 获取某一个国家的所有茶叶品种
88+
* @param contryName
89+
* @returns {Array}
90+
*/
91+
export function getTeas(contryName) {
92+
const index = data.contries.find(c => c.name === contryName)
93+
return data.contries[index].teaIds.map(id => teas[id])
94+
}
95+
96+
export function getTeasByContryId(contryId) {
97+
return data.contries[contryId].teas.map(teaId => data.teas[teaId])
98+
}
99+
100+
export function getTea(teaId) {
101+
const index = teas.findIndex(tea => tea.id === teaId)
102+
const tea = teas[index]
103+
return tea
104+
}
105+
106+
107+
/**
108+
* 创建新的名茶对象,并返回该对象
109+
* @param name
110+
* @param contryName
111+
* @returns {{teaId: Number, contryId}}
112+
*/
113+
export function createTea(name, contryName) {
114+
const newTea = { name: name, id: teas.length }
115+
teas.push(newTea)
116+
117+
const contry = data.contries.find(contry => contry.name === contryName)
118+
contry.teaIds.push(newTea.id)
119+
120+
return { teaId: teas.length, contryId: contry.id }
121+
}
122+
123+
124+
125+
126+
127+
128+
129+
130+
131+
132+
133+
134+
135+
136+
137+
138+
139+
140+
141+
142+
143+
144+
145+
146+
147+
148+
149+
150+
151+
152+
153+
154+
155+
156+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# 国家
2+
type Contry implements Node {
3+
# The ID of an object
4+
id: ID!
5+
contryId: String
6+
7+
# 国家名称
8+
name: String
9+
10+
# 属于这个国家的著名茶叶
11+
teas(after: String, first: Int, before: String, last: Int): TeaConnection
12+
}
13+
14+
input CreateTeaInput {
15+
teaName: String!
16+
contryId: ID!
17+
clientMutationId: String
18+
}
19+
20+
type CreateTeaPayload {
21+
newTeaEdge: TeaEdge
22+
contry: Contry
23+
clientMutationId: String
24+
}
25+
26+
type Mutation {
27+
createTea(input: CreateTeaInput!): CreateTeaPayload
28+
}
29+
30+
# An object with an ID
31+
interface Node {
32+
# The id of the object.
33+
id: ID!
34+
}
35+
36+
# Information about pagination in a connection.
37+
type PageInfo {
38+
# When paginating forwards, are there more items?
39+
hasNextPage: Boolean!
40+
41+
# When paginating backwards, are there more items?
42+
hasPreviousPage: Boolean!
43+
44+
# When paginating backwards, the cursor to continue.
45+
startCursor: String
46+
47+
# When paginating forwards, the cursor to continue.
48+
endCursor: String
49+
}
50+
51+
type Query {
52+
# Fetches an object given its ID
53+
node(
54+
# The ID of an object
55+
id: ID!
56+
): Node
57+
contry(id: Int): Contry
58+
}
59+
60+
type Tea implements Node {
61+
# The ID of an object
62+
id: ID!
63+
64+
# 茶叶的名字
65+
name: String
66+
}
67+
68+
# A connection to a list of items.
69+
type TeaConnection {
70+
# Information to aid in pagination.
71+
pageInfo: PageInfo!
72+
73+
# A list of edges.
74+
edges: [TeaEdge]
75+
}
76+
77+
# An edge in a connection.
78+
type TeaEdge {
79+
# The item at the end of the edge
80+
node: Tea
81+
82+
# A cursor for use in pagination
83+
cursor: String!
84+
}

0 commit comments

Comments
 (0)