Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增 relay初体验的demo #65

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
bower_components/
bower_components/
./idea
31 changes: 31 additions & 0 deletions Appendix04/Relay-Example/demo1-基本/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
BSD License

For Relay Starter Kit software

Copyright (c) 2013-2015, Facebook, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name Facebook nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 changes: 33 additions & 0 deletions Appendix04/Relay-Example/demo1-基本/PATENTS
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Additional Grant of Patent Rights Version 2

"Software" means the Relay Starter Kit software distributed by Facebook, Inc.

Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software
("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable
(subject to the termination provision below) license under any Necessary
Claims, to make, have made, use, sell, offer to sell, import, and otherwise
transfer the Software. For avoidance of doubt, no license is granted under
Facebook's rights in any patent claims that are infringed by (i) modifications
to the Software made by you or any third party or (ii) the Software in
combination with any software or other technology.

The license granted hereunder will terminate, automatically and without notice,
if you (or any of your subsidiaries, corporate affiliates or agents) initiate
directly or indirectly, or take a direct financial interest in, any Patent
Assertion: (i) against Facebook or any of its subsidiaries or corporate
affiliates, (ii) against any party if such Patent Assertion arises in whole or
in part from any software, technology, product or service of Facebook or any of
its subsidiaries or corporate affiliates, or (iii) against any party relating
to the Software. Notwithstanding the foregoing, if Facebook or any of its
subsidiaries or corporate affiliates files a lawsuit alleging patent
infringement against you in the first instance, and you respond by filing a
patent infringement counterclaim in that lawsuit against that party that is
unrelated to the Software, the license granted hereunder will not terminate
under section (i) of this paragraph due to such counterclaim.

A "Necessary Claim" is a claim of a patent owned by Facebook that is
necessarily infringed by the Software standing alone.

A "Patent Assertion" is any lawsuit or other action alleging direct, indirect,
or contributory infringement or inducement to infringe any patent, including a
cross-claim or counterclaim.
34 changes: 34 additions & 0 deletions Appendix04/Relay-Example/demo1-基本/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Relay Starter Kit

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).

## Installation

```
npm install
```

## Running

Start a local server:

```
npm start
```

## Developing

Any changes you make to files in the `js/` directory will cause the server to
automatically rebuild the app and refresh your browser.

If at any time you make changes to `data/schema.js`, stop the server,
regenerate `data/schema.json`, and restart the server:

```
npm run update-schema
npm start
```

## License

Relay Starter Kit is [BSD licensed](./LICENSE). We also provide an additional [patent grant](./PATENTS).
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var getbabelRelayPlugin = require('babel-relay-plugin');
var schema = require('../data/schema.json');

module.exports = getbabelRelayPlugin(schema.data);
12 changes: 12 additions & 0 deletions Appendix04/Relay-Example/demo1-基本/data/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type Query {
store: Store
}

type Store {
teas: [Tea]
}

type Tea {
name: String
steepingTime: Int
}
71 changes: 71 additions & 0 deletions Appendix04/Relay-Example/demo1-基本/data/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 引入函式库
import {
GraphQLInt,
GraphQLList,
GraphQLObjectType,
GraphQLSchema,
GraphQLString,
} from 'graphql';

import {
connectionArgs,
connectionDefinitions,
connectionFromArray,
fromGlobalId,
globalIdField,
mutationWithClientMutationId,
nodeDefinitions,
} from 'graphql-relay';

// client side 暂存 store,GraphQL Server reponse 会更新 store,再透过 props 传递给 Component
const STORE = {
teas: [
{ name: 'Bancha', steepingTime: 2 },
{ name: 'Sencha Makoto', steepingTime: 2 },
{ name: 'Milk Oolong', steepingTime: 3 },
{ name: 'Jasmine Phoenix Pearls', steepingTime: 3 },
{ name: 'Gunpowder Golden Temple', steepingTime: 3 },
{ name: 'Pu Erh First Grade', steepingTime: 4 },
{ name: 'Kenya Milima', steepingTime: 5 },
{ name: 'Assam Hatimara', steepingTime: 5 },
{ name: 'Golden Tip Yunnan', steepingTime: 5 },
{ name: 'Earl Grey Blue Star', steepingTime: 5 },
{ name: 'Ceylon New Vithanakande', steepingTime: 5 },
],
};

// 设计 GraphQL Type
var teaType = new GraphQLObjectType({
name: 'Tea',
fields: () => ({
name: { type: GraphQLString },
steepingTime: { type: GraphQLInt },
}),
});

// 将 Tea 整合进来
var storeType = new GraphQLObjectType({
name: 'Store',
fields: () => ({
teas: { type: new GraphQLList(teaType) },
}),
});

var queryType = new GraphQLObjectType({
name: 'Query',
fields: () => ({
store: {
type: storeType,
resolve: () => STORE,
},
})
})

var { connectionType : teaConnection } = connectionDefinitions({
name: 'Tea', nodeType: teaType
})

// 输出 GraphQL Schema
export var Schema = new GraphQLSchema({
query: queryType
});
Loading