├── .watchmanconfig ├── server ├── models │ ├── index.js │ └── post.js ├── updateSchema.js ├── schema │ ├── schema.graphql │ └── schema.js └── server.js ├── app.json ├── .gitattributes ├── .gitignore ├── .idea ├── copyright │ └── profiles_settings.xml ├── vcs.xml ├── modules.xml ├── BakBak-Relay-RN.iml ├── compiler.xml ├── misc.xml └── workspace.xml ├── jsconfig.json ├── App.test.js ├── .babelrc ├── .eslintrc ├── App.js ├── client ├── components │ └── post │ │ ├── PostList.js │ │ └── PostItem.js ├── main.js ├── screens │ └── PostListScreen.js └── api │ └── Api.js ├── .flowconfig ├── package.json └── README.md /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /server/models/index.js: -------------------------------------------------------------------------------- 1 | import './post'; -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "expo": { 3 | "sdkVersion": "17.0.0" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .expo/ 3 | npm-debug.* 4 | .DS_Store 5 | __generated__/ -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowJs": true, 4 | "allowSyntheticDefaultImports": true 5 | }, 6 | "exclude": [ 7 | "node_modules" 8 | ] 9 | } -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import App from './App'; 3 | 4 | import renderer from 'react-test-renderer'; 5 | 6 | it('renders without crashing', () => { 7 | const rendered = renderer.create().toJSON(); 8 | expect(rendered).toBeTruthy(); 9 | }); 10 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "passPerPreset": true, 3 | "plugins": [ 4 | [ 5 | "relay", { 6 | "schema": "server/schema/schema.graphql" 7 | } 8 | ] 9 | ], 10 | "presets": [ 11 | "react-native", 12 | "react-native-stage-0/decorator-support" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "fbjs", 3 | "rules": { 4 | "indent": [ 2, "tab" ], 5 | "no-tabs": 0, 6 | "react/jsx-filename-extension": [ 1, { 7 | "extensions": [ ".js", ".jsx" ] 8 | } 9 | ], 10 | "react/jsx-indent": [ 2, "tab" ], 11 | "react/jsx-indent-props": [ 2, "tab" ] 12 | } 13 | } -------------------------------------------------------------------------------- /App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { StyleSheet, View } from 'react-native'; 3 | 4 | import Main from './client/main'; 5 | 6 | export default class App extends React.Component { 7 | render() { 8 | return ( 9 | 10 |
11 | 12 | ); 13 | } 14 | } 15 | 16 | const styles = StyleSheet.create({ 17 | container: { 18 | flex: 1, 19 | backgroundColor: '#fff', 20 | alignItems: 'center', 21 | justifyContent: 'center', 22 | }, 23 | }); 24 | -------------------------------------------------------------------------------- /.idea/BakBak-Relay-RN.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /client/components/post/PostList.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import React, { Component } from 'react'; 3 | import { Text, View, FlatList } from 'react-native'; 4 | import PropTypes from 'prop-types'; 5 | 6 | import PostItem from './PostItem'; 7 | 8 | class PostList extends Component { 9 | 10 | keyExtractor = (item, index) => item.id; 11 | renderItem = (post) => ( 12 | this.props.onPostSelect(post)} /> 13 | ); 14 | 15 | render() { 16 | return ( 17 | 18 | 19 | Category 1 20 | this.renderItem(item)} 25 | keyExtractor={this.keyExtractor} 26 | /> 27 | 28 | 29 | ); 30 | } 31 | } 32 | 33 | export default PostList; 34 | -------------------------------------------------------------------------------- /server/updateSchema.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env babel-node 2 | /** 3 | * This file provided by Facebook is for non-commercial testing and evaluation 4 | * purposes only. Facebook reserves all rights not expressly granted. 5 | * 6 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 7 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 8 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 9 | * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 10 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 11 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | import fs from 'fs'; 15 | import path from 'path'; 16 | import { schema } from './schema/schema'; 17 | import { printSchema } from 'graphql'; 18 | 19 | const schemaPath = path.resolve(__dirname, './schema/schema.graphql'); 20 | 21 | fs.writeFileSync(schemaPath, printSchema(schema)); 22 | 23 | console.log('Wrote ' + schemaPath); 24 | -------------------------------------------------------------------------------- /server/schema/schema.graphql: -------------------------------------------------------------------------------- 1 | input CreatePostInput { 2 | title: String! 3 | details: String 4 | clientMutationId: String 5 | } 6 | 7 | type CreatePostPayload { 8 | post: Post 9 | clientMutationId: String 10 | } 11 | 12 | # A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the 13 | # `date-time` format outlined in section 5.6 of the RFC 3339 profile of the ISO 14 | # 8601 standard for representation of dates and times using the Gregorian calendar. 15 | scalar DateTime 16 | 17 | type Mutation { 18 | createPost(input: CreatePostInput!): CreatePostPayload 19 | } 20 | 21 | # An object with an ID 22 | interface Node { 23 | # The id of the object. 24 | id: ID! 25 | } 26 | 27 | type Post implements Node { 28 | # The ID of an object 29 | id: ID! 30 | title: String 31 | details: String 32 | likes: Int 33 | dislikes: Int 34 | createdAt: DateTime 35 | } 36 | 37 | type Query { 38 | posts: [Post] 39 | 40 | # Fetches an object given its ID 41 | node( 42 | # The ID of an object 43 | id: ID! 44 | ): Node 45 | } 46 | -------------------------------------------------------------------------------- /client/main.js: -------------------------------------------------------------------------------- 1 | import 'isomorphic-fetch'; 2 | import React, { Component } from 'react'; 3 | import { QueryRenderer, graphql } from 'react-relay'; 4 | import { Text, View } from 'react-native'; 5 | 6 | import PostListScreen from './screens/PostListScreen'; 7 | import Api from './api/Api'; 8 | 9 | const baseUrl = 'http://192.168.1.132:8080'; 10 | 11 | // const baseUrl = 'http://172.20.10.4:8080'; 12 | //const baseUrl = 'http://172.26.130.43:8080'; 13 | 14 | class Main extends Component { 15 | render() { 16 | const environment = Api.create({ baseUrl }).environment; 17 | return ( 18 | { 32 | if (props) { 33 | return ; 34 | 35 | } else if (error) { 36 | console.log(error); 37 | return error ; 38 | } 39 | return Loading ; 40 | }} 41 | /> 42 | ); 43 | } 44 | } 45 | 46 | export default Main; -------------------------------------------------------------------------------- /client/screens/PostListScreen.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import React, { Component } from 'react'; 3 | import { StyleSheet, ScrollView, View } from 'react-native'; 4 | import { createFragmentContainer, graphql } from 'react-relay'; 5 | 6 | import PostList from '../components/post/PostList'; 7 | 8 | class PostListScreen extends Component { 9 | static navigationOptions = { 10 | tabBarLabel: 'Post List', 11 | }; 12 | 13 | onPostSelect = (post) => { 14 | 15 | } 16 | render() { 17 | const { posts} = this.props; 18 | if (!posts) { 19 | return ; 20 | } 21 | return ( 22 | 23 | 24 | 25 | 26 | 27 | 28 | ); 29 | } 30 | } 31 | 32 | const styles = StyleSheet.create({ 33 | container: { 34 | flex: 1, 35 | marginTop: 20, 36 | } 37 | }); 38 | 39 | export default createFragmentContainer(PostListScreen, graphql` 40 | fragment PostListScreen_posts on Post @relay(plural: true) { 41 | id 42 | title 43 | details 44 | } 45 | `); -------------------------------------------------------------------------------- /server/models/post.js: -------------------------------------------------------------------------------- 1 | import mongoose from 'mongoose'; 2 | const Schema = mongoose.Schema; 3 | 4 | const PostSchema = new Schema({ 5 | title: { 6 | type: String, 7 | }, 8 | details: { 9 | type: String, 10 | }, 11 | views: { 12 | type: Number, 13 | default: 0, 14 | }, 15 | likes: { 16 | type: Number, 17 | default: 0, 18 | }, 19 | dislikes: { 20 | type: Number, 21 | default: 0, 22 | }, 23 | createdAt: { 24 | type: Date, 25 | }, 26 | comments: [{ 27 | type: Schema.Types.ObjectId, 28 | ref: 'comment', 29 | }], 30 | // author: AuthorSchema, 31 | }); 32 | 33 | PostSchema.statics.findComments = function(postId) { 34 | return this.findById(postId) 35 | .populate('comments') 36 | .then(post => post.comments); 37 | }; 38 | 39 | PostSchema.statics.addComment = function(postId, { text }) { 40 | const Comment = mongoose.model('comment'); 41 | return this.findById(postId).then(post => { 42 | const comment = new Comment({ text, createdAt: new Date() }); 43 | post.comments.push(comment); 44 | return Promise.all([comment.save(), post.save()]).then(([, newPost]) => newPost); 45 | // return comment.save().then(newComment => 46 | // this.findByIdAndUpdate(postId, { $push: { comments: newComment } }) 47 | // ); 48 | }); 49 | }; 50 | 51 | const Post = mongoose.model('post', PostSchema); 52 | 53 | export default Post; 54 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 19 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /client/api/Api.js: -------------------------------------------------------------------------------- 1 | import 'isomorphic-fetch'; 2 | import { 3 | Environment, 4 | Network, 5 | RecordSource, 6 | Store, 7 | fetchQuery, 8 | commitMutation, 9 | commitLocalUpdate, 10 | } from 'relay-runtime'; 11 | 12 | /** 13 | * Creates a set of helper methods for working with REST and/or GraphQL APIs. 14 | */ 15 | function create({ baseUrl, headers = {} }) { 16 | // Default options for the Fetch API 17 | // https://developer.mozilla.org/docs/Web/API/Fetch_API/Using_Fetch 18 | const defaults = { 19 | mode: baseUrl ? 'cors' : 'same-origin', 20 | credentials: baseUrl ? 'include' : 'same-origin', 21 | headers: { 22 | ...headers, 23 | Accept: 'application/json', 24 | 'Content-Type': 'application/json', 25 | }, 26 | }; 27 | 28 | // Configure Relay environment 29 | const environment = new Environment({ 30 | handlerProvider: null, 31 | network: Network.create((operation, variables /* cacheConfig, uploadables */) => 32 | fetch(`${baseUrl}/graphql`, { 33 | ...defaults, 34 | method: 'POST', 35 | body: JSON.stringify({ 36 | query: operation.text, // GraphQL text from input 37 | variables, 38 | }), 39 | }).then(response => response.json())), 40 | store: new Store(new RecordSource()), 41 | }); 42 | 43 | return { 44 | environment, 45 | fetch: (url, options) => fetch(`${baseUrl}${url}`, { 46 | ...defaults, 47 | ...options, 48 | headers: { 49 | ...defaults.headers, 50 | ...(options && options.headers), 51 | }, 52 | }), 53 | fetchQuery: fetchQuery.bind(undefined, environment), 54 | commitMutation: commitMutation.bind(undefined, environment), 55 | commitLocalUpdate: commitLocalUpdate.bind(undefined, environment), 56 | }; 57 | } 58 | 59 | export default { create }; -------------------------------------------------------------------------------- /server/server.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file provided by Facebook is for non-commercial testing and evaluation 3 | * purposes only. Facebook reserves all rights not expressly granted. 4 | * 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 8 | * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 9 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 10 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | */ 12 | import 'isomorphic-fetch'; 13 | import models from './models/index'; 14 | 15 | import express from 'express'; 16 | import graphQLHTTP from 'express-graphql'; 17 | import passport from 'passport'; 18 | import mongoose from 'mongoose'; 19 | import session from 'express-session'; 20 | import connectMongo from 'connect-mongo'; 21 | 22 | import {schema} from './schema/schema'; 23 | 24 | const MongoStore = connectMongo(session); 25 | const GRAPHQL_PORT = 8080; 26 | // Expose a GraphQL endpoint 27 | const app = express(); 28 | // Replace with your mongoLab URI 29 | const MONGO_URI = 'YOUR SERVER URI'; 30 | // Mongoose's built in promise library is deprecated, replace it with ES2015 Promise 31 | mongoose.Promise = global.Promise; 32 | 33 | // Connect to the mongoDB instance and log a message 34 | // on success or failure 35 | mongoose.connect(MONGO_URI); 36 | mongoose.connection 37 | .once('open', () => console.log('Connected to MongoLab instance.')) 38 | .on('error', error => console.log('Error connecting to MongoLab:', error)); 39 | 40 | // app.use(cors()); 41 | app.use('/', graphQLHTTP({ 42 | schema, 43 | graphiql: true, 44 | pretty: true, 45 | })); 46 | 47 | app.listen(GRAPHQL_PORT, () => console.log( 48 | `GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}` 49 | )); 50 | 51 | export default app; 52 | -------------------------------------------------------------------------------- /client/components/post/PostItem.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | import React, { Component } from 'react'; 3 | import { Text, View, StyleSheet, TouchableOpacity } from 'react-native'; 4 | import { Card } from 'react-native-elements'; 5 | import { MaterialIcons } from '@expo/vector-icons'; 6 | import PropTypes from 'prop-types'; 7 | 8 | class PostItem extends Component { 9 | 10 | render() { 11 | const post = this.props.post; 12 | return ( 13 | this.props.onCardSelect(post)}> 14 | 15 | 16 | { post.title } 17 | 18 | {/* 19 | { item.author.name } 20 | */} 21 | 22 | {post.views} 23 | 24 | {post.likes - post.dislikes} 25 | 26 | 27 | 28 | 29 | ); 30 | } 31 | } 32 | 33 | const styles = StyleSheet.create({ 34 | cardContainer: { 35 | width: 130, 36 | height: 130, 37 | borderWidth: 0.5, 38 | borderColor: '#f2f2f2', 39 | flexDirection: 'column', 40 | backgroundColor: '#e6eeff', 41 | }, 42 | cardTitleContainer: { 43 | height: 85, 44 | }, 45 | cardTitleText: { 46 | fontSize: 14, 47 | color: '#595959', 48 | paddingLeft: 4, 49 | paddingRight: 4, 50 | }, 51 | cardAuthorContainer: { 52 | }, 53 | cardAuthorText: { 54 | fontSize: 14, 55 | color: '#737373', 56 | paddingLeft: 4, 57 | paddingRight: 4, 58 | alignItems: 'flex-end', 59 | justifyContent: 'flex-end', 60 | }, 61 | buttonsContainer: { 62 | flexDirection: 'row', 63 | }, 64 | buttonTextStyle: { 65 | color: '#737373', 66 | } 67 | }); 68 | 69 | export default PostItem; 70 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore unexpected extra "@providesModule" 9 | .*/node_modules/.*/node_modules/fbjs/.* 10 | 11 | ; Ignore duplicate module providers 12 | ; For RN Apps installed via npm, "Libraries" folder is inside 13 | ; "node_modules/react-native" but in the source repo it is in the root 14 | .*/Libraries/react-native/React.js 15 | .*/Libraries/react-native/ReactNative.js 16 | 17 | ; Additional create-react-native-app ignores 18 | 19 | ; Ignore duplicate module providers 20 | .*/node_modules/fbemitter/lib/* 21 | 22 | ; Ignore misbehaving dev-dependencies 23 | .*/node_modules/xdl/build/* 24 | .*/node_modules/reqwest/tests/* 25 | 26 | ; Ignore missing expo-sdk dependencies (temporarily) 27 | ; https://github.com/expo/expo/issues/162 28 | .*/node_modules/expo/src/* 29 | 30 | ; Ignore react-native-fbads dependency of the expo sdk 31 | .*/node_modules/react-native-fbads/* 32 | 33 | [include] 34 | 35 | [libs] 36 | node_modules/react-native/Libraries/react-native/react-native-interface.js 37 | node_modules/react-native/flow 38 | flow/ 39 | 40 | [options] 41 | module.system=haste 42 | 43 | emoji=true 44 | 45 | experimental.strict_type_args=true 46 | 47 | munge_underscores=true 48 | 49 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 50 | 51 | suppress_type=$FlowIssue 52 | suppress_type=$FlowFixMe 53 | suppress_type=$FixMe 54 | 55 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-2]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 56 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-2]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 57 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 58 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 59 | 60 | unsafe.enable_getters_and_setters=true 61 | 62 | [version] 63 | ^0.42.0 64 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bakbak-relay-rn", 3 | "version": "0.1.0", 4 | "private": true, 5 | "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js", 6 | "scripts": { 7 | "server": "babel-node ./server/server.js", 8 | "build": "relay-compiler --src ./client/ --schema ./server/schema/schema.graphql", 9 | "update-schema": "babel-node ./server/updateSchema.js", 10 | "lint": "eslint ./js", 11 | "start": "react-native-scripts start", 12 | "eject": "react-native-scripts eject", 13 | "android": "react-native-scripts android", 14 | "ios": "react-native-scripts ios", 15 | "test": "node node_modules/jest/bin/jest.js --watch" 16 | }, 17 | "jest": { 18 | "preset": "jest-expo" 19 | }, 20 | "dependencies": { 21 | "babel-preset-react-native-stage-0": "^1.0.1", 22 | "bcrypt-nodejs": "0.0.3", 23 | "body-parser": "^1.17.2", 24 | "classnames": "2.2.5", 25 | "connect-mongo": "^1.3.2", 26 | "expo": "^17.0.0", 27 | "express": "^4.15.2", 28 | "express-graphql": "^0.6.4", 29 | "express-session": "^1.15.3", 30 | "graphql": "^0.9.1", 31 | "graphql-iso-date": "^3.2.0", 32 | "graphql-relay": "^0.5.1", 33 | "isomorphic-fetch": "^2.2.1", 34 | "mongoose": "^4.10.7", 35 | "passport": "^0.3.2", 36 | "passport-local": "^1.0.0", 37 | "prop-types": "^15.5.8", 38 | "react": "16.0.0-alpha.6", 39 | "react-native": "^0.44.0", 40 | "react-native-elements": "^0.13.0", 41 | "react-navigation": "1.0.0-beta.11", 42 | "react-relay": "^1.0.0-a" 43 | }, 44 | "devDependencies": { 45 | "babel-cli": "^6.24.1", 46 | "babel-eslint": "^7.2.3", 47 | "babel-jest": "19.0.0", 48 | "babel-plugin-relay": "1.0.1-rc.3", 49 | "babel-preset-react-native": "1.9.1", 50 | "eslint": "^3.19.0", 51 | "eslint-config-fbjs": "1.1.1", 52 | "eslint-plugin-babel": "^4.1.1", 53 | "eslint-plugin-flowtype": "^2.32.1", 54 | "eslint-plugin-import": "^2.2.0", 55 | "eslint-plugin-react": "^6.10.3", 56 | "eslint-plugin-react-native": "^2.3.2", 57 | "jest": "18.1.0", 58 | "jest-expo": "~1.0.1", 59 | "lint-staged": "^3.4.0", 60 | "prettier": "^1.2.2", 61 | "react-devtools": "^2.1.0", 62 | "react-native-scripts": "0.0.31", 63 | "react-test-renderer": "16.0.0-alpha.6", 64 | "relay-compiler": "^1.0.0-a" 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /server/schema/schema.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file provided by Facebook is for non-commercial testing and evaluation 3 | * purposes only. Facebook reserves all rights not expressly granted. 4 | * 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 8 | * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 9 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 10 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | */ 12 | import 'isomorphic-fetch'; 13 | import { 14 | GraphQLBoolean, 15 | GraphQLID, 16 | GraphQLInt, 17 | GraphQLList, 18 | GraphQLNonNull, 19 | GraphQLObjectType, 20 | GraphQLSchema, 21 | GraphQLString, 22 | } from 'graphql'; 23 | 24 | import { 25 | connectionArgs, 26 | connectionDefinitions, 27 | connectionFromArray, 28 | cursorForObjectInConnection, 29 | fromGlobalId, 30 | globalIdField, 31 | mutationWithClientMutationId, 32 | nodeDefinitions, 33 | toGlobalId, 34 | } from 'graphql-relay'; 35 | import { GraphQLDateTime } from 'graphql-iso-date'; 36 | 37 | import Post from '../models/post'; 38 | 39 | const {nodeInterface, nodeField} = nodeDefinitions( 40 | (globalId) => { 41 | const {type, id} = fromGlobalId(globalId); 42 | // if (type === 'User') { 43 | // return getUser(id); 44 | // } else 45 | if (type === 'Post') { 46 | return Post.findById(id); 47 | } 48 | return null; 49 | }, 50 | (obj) => { 51 | // if (obj instanceof User) { 52 | // return GraphQLUser; 53 | // } else 54 | if (obj instanceof Post) { 55 | return GraphQLPost; 56 | } 57 | return null; 58 | } 59 | ); 60 | 61 | const GraphQLPost = new GraphQLObjectType({ 62 | name: 'Post', 63 | fields: { 64 | id: globalIdField('Post'), 65 | title: { type: GraphQLString }, 66 | details: { type: GraphQLString }, 67 | likes: { type: GraphQLInt }, 68 | dislikes: { type: GraphQLInt }, 69 | createdAt: { type: GraphQLDateTime } 70 | }, 71 | interfaces: [nodeInterface], 72 | }); 73 | 74 | const { 75 | connectionType: PostConnection, 76 | edgeType: GraphQLPostEdge, 77 | } = connectionDefinitions({ 78 | name: 'Post', 79 | nodeType: GraphQLPost, 80 | }); 81 | 82 | // const GraphQLUser = new GraphQLObjectType({ 83 | // name: 'User', 84 | // fields: { 85 | // id: globalIdField('User'), 86 | // posts:{ 87 | // type: PostConnection, 88 | // args: connectionArgs, 89 | // resolve: (user, args) => connectionFromArray(getPosts(), args), 90 | // }, 91 | // }, 92 | // interfaces: [nodeInterface], 93 | // }); 94 | 95 | const Query = new GraphQLObjectType({ 96 | name: 'Query', 97 | fields: { 98 | // viewer: { 99 | // type: GraphQLUser, 100 | // resolve: () => getViewer(), 101 | // }, 102 | posts: { 103 | type: new GraphQLList(GraphQLPost), 104 | resolve: () => Post.find({}), 105 | }, 106 | node: nodeField, 107 | }, 108 | }); 109 | 110 | const GraphQLCreatePostMutation = mutationWithClientMutationId({ 111 | name: 'CreatePost', 112 | inputFields: { 113 | title: { type: new GraphQLNonNull(GraphQLString)}, 114 | details: { type: GraphQLString }, 115 | }, 116 | outputFields: { 117 | post: { 118 | type: GraphQLPost, 119 | resolve: (post) => post, 120 | }, 121 | }, 122 | mutateAndGetPayload: ({ title, details }) => { 123 | const post = (new Post({ title, details, createdAt: new Date() })).save(); 124 | return post; 125 | }, 126 | }); 127 | 128 | const Mutation = new GraphQLObjectType({ 129 | name: 'Mutation', 130 | fields: { 131 | createPost: GraphQLCreatePostMutation, 132 | }, 133 | }); 134 | 135 | export const schema = new GraphQLSchema({ 136 | query: Query, 137 | mutation: Mutation, 138 | }); 139 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | I created this repo for anyone who wants to run relay app using local GraphQL server. I could not find a single repo which provide information on how to connect a Relay app with a GraphQL server which is not hosted on third party providers like Graphcool etc. 2 | 3 | This repo is not how to setup individual pieces like mlab (or mongodb on local machine). I ran this on my computer and there were no issues. Few steps to make it work. 4 | 5 | 1) Download the repo 6 | 2) Goto the root of the repo. Download the packages -> Yarn install or npm install 7 | 3) Goto server/server.js. Register for mlab account or provide your local mongodb address for MONGO_URI 8 | 4) Goto command promot and run this command -> ipconfig 9 | 5) change the baseurl (in client/main.js ) with Ip4 address. 10 | 6) yarn update-schema 11 | 7) yarn build 12 | 8) yarn server -> it will start your local graphql and connect with mongo server (either locally or with mlab) 13 | 9) Open the application through expo 14 | 15 | If it is not connected to your graphql server then there could be 2 issues: 16 | 1) make sure that you are on same network i.e. your mobile device and laptop. Make sure that IP address is correct in Step 5 17 | 2) there are no error in step 8 i.e. Graphql Server is running and app is connecting to mongodb. 18 | 19 | This project was bootstrapped with [Create React Native App](https://github.com/react-community/create-react-native-app). 20 | 21 | Below you'll find information about performing common tasks. The most recent version of this guide is available [here](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md). 22 | 23 | ## Table of Contents 24 | 25 | * [Updating to New Releases](#updating-to-new-releases) 26 | * [Available Scripts](#available-scripts) 27 | * [npm start](#npm-start) 28 | * [npm test](#npm-test) 29 | * [npm run ios](#npm-run-ios) 30 | * [npm run android](#npm-run-android) 31 | * [npm run eject](#npm-run-eject) 32 | * [Writing and Running Tests](#writing-and-running-tests) 33 | * [Environment Variables](#environment-variables) 34 | * [Configuring Packager IP Address](#configuring-packager-ip-address) 35 | * [Adding Flow](#adding-flow) 36 | * [Customizing App Display Name and Icon](#customizing-app-display-name-and-icon) 37 | * [Sharing and Deployment](#sharing-and-deployment) 38 | * [Publishing to Expo's React Native Community](#publishing-to-expos-react-native-community) 39 | * [Building an Expo "standalone" app](#building-an-expo-standalone-app) 40 | * [Ejecting from Create React Native App](#ejecting-from-create-react-native-app) 41 | * [Build Dependencies (Xcode & Android Studio)](#build-dependencies-xcode-android-studio) 42 | * [Should I Use ExpoKit?](#should-i-use-expokit) 43 | * [Troubleshooting](#troubleshooting) 44 | * [Networking](#networking) 45 | * [iOS Simulator won't open](#ios-simulator-wont-open) 46 | * [QR Code does not scan](#qr-code-does-not-scan) 47 | 48 | ## Updating to New Releases 49 | 50 | You should only need to update the global installation of `create-react-native-app` very rarely, ideally never. 51 | 52 | Updating the `react-native-scripts` dependency of your app should be as simple as bumping the version number in `package.json` and reinstalling your project's dependencies. 53 | 54 | Upgrading to a new version of React Native requires updating the `react-native`, `react`, and `expo` package versions, and setting the correct `sdkVersion` in `app.json`. See the [versioning guide](https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md) for up-to-date information about package version compatibility. 55 | 56 | ## Available Scripts 57 | 58 | If Yarn was installed when the project was initialized, then dependencies will have been installed via Yarn, and you should probably use it to run these commands as well. Unlike dependency installation, command running syntax is identical for Yarn and NPM at the time of this writing. 59 | 60 | ### `npm start` 61 | 62 | Runs your app in development mode. 63 | 64 | Open it in the [Expo app](https://expo.io) on your phone to view it. It will reload if you save edits to your files, and you will see build errors and logs in the terminal. 65 | 66 | Sometimes you may need to reset or clear the React Native packager's cache. To do so, you can pass the `--reset-cache` flag to the start script: 67 | 68 | ``` 69 | npm start -- --reset-cache 70 | # or 71 | yarn start -- --reset-cache 72 | ``` 73 | 74 | #### `npm test` 75 | 76 | Runs the [jest](https://github.com/facebook/jest) test runner on your tests. 77 | 78 | #### `npm run ios` 79 | 80 | Like `npm start`, but also attempts to open your app in the iOS Simulator if you're on a Mac and have it installed. 81 | 82 | #### `npm run android` 83 | 84 | Like `npm start`, but also attempts to open your app on a connected Android device or emulator. Requires an installation of Android build tools (see [React Native docs](https://facebook.github.io/react-native/docs/getting-started.html) for detailed setup). We also recommend installing Genymotion as your Android emulator. Once you've finished setting up the native build environment, there are two options for making the right copy of `adb` available to Create React Native App: 85 | 86 | ##### Using Android Studio's `adb` 87 | 88 | 1. Make sure that you can run adb from your terminal. 89 | 2. Open Genymotion and navigate to `Settings -> ADB`. Select “Use custom Android SDK tools” and update with your [Android SDK directory](https://stackoverflow.com/questions/25176594/android-sdk-location). 90 | 91 | ##### Using Genymotion's `adb` 92 | 93 | 1. Find Genymotion’s copy of adb. On macOS for example, this is normally `/Applications/Genymotion.app/Contents/MacOS/tools/`. 94 | 2. Add the Genymotion tools directory to your path (instructions for [Mac](http://osxdaily.com/2014/08/14/add-new-path-to-path-command-line/), [Linux](http://www.computerhope.com/issues/ch001647.htm), and [Windows](https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/)). 95 | 3. Make sure that you can run adb from your terminal. 96 | 97 | #### `npm run eject` 98 | 99 | This will start the process of "ejecting" from Create React Native App's build scripts. You'll be asked a couple of questions about how you'd like to build your project. 100 | 101 | **Warning:** Running eject is a permanent action (aside from whatever version control system you use). An ejected app will require you to have an [Xcode and/or Android Studio environment](https://facebook.github.io/react-native/docs/getting-started.html) set up. 102 | 103 | ## Customizing App Display Name and Icon 104 | 105 | You can edit `app.json` to include [configuration keys](https://docs.expo.io/versions/latest/guides/configuration.html) under the `expo` key. 106 | 107 | To change your app's display name, set the `expo.name` key in `app.json` to an appropriate string. 108 | 109 | To set an app icon, set the `expo.icon` key in `app.json` to be either a local path or a URL. It's recommended that you use a 512x512 png file with transparency. 110 | 111 | ## Writing and Running Tests 112 | 113 | This project is set up to use [jest](https://facebook.github.io/jest/) for tests. You can configure whatever testing strategy you like, but jest works out of the box. Create test files in directories called `__tests__` to have the files loaded by jest. See the [the template project](https://github.com/react-community/create-react-native-app/tree/master/react-native-scripts/template/__tests__) for an example test. The [jest documentation](https://facebook.github.io/jest/docs/getting-started.html) is also a wonderful resource, as is the [React Native testing tutorial](https://facebook.github.io/jest/docs/tutorial-react-native.html). 114 | 115 | ## Environment Variables 116 | 117 | You can configure some of Create React Native App's behavior using environment variables. 118 | 119 | ### Configuring Packager IP Address 120 | 121 | When starting your project, you'll see something like this for your project URL: 122 | 123 | ``` 124 | exp://192.168.0.2:19000 125 | ``` 126 | 127 | The "manifest" at that URL tells the Expo app how to retrieve and load your app's JavaScript bundle, so even if you load it in the app via a URL like `exp://localhost:19000`, the Expo client app will still try to retrieve your app at the IP address that the start script provides. 128 | 129 | In some cases, this is less than ideal. This might be the case if you need to run your project inside of a virtual machine and you have to access the packager via a different IP address than the one which prints by default. In order to override the IP address or hostname that is detected by Create React Native App, you can specify your own hostname via the `REACT_NATIVE_PACKAGER_HOSTNAME` environment variable: 130 | 131 | Mac and Linux: 132 | 133 | ``` 134 | REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' npm start 135 | ``` 136 | 137 | Windows: 138 | ``` 139 | set REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' 140 | npm start 141 | ``` 142 | 143 | The above example would cause the development server to listen on `exp://my-custom-ip-address-or-hostname:19000`. 144 | 145 | ## Adding Flow 146 | 147 | Flow is a static type checker that helps you write code with fewer bugs. Check out this [introduction to using static types in JavaScript](https://medium.com/@preethikasireddy/why-use-static-types-in-javascript-part-1-8382da1e0adb) if you are new to this concept. 148 | 149 | React Native works with [Flow](http://flowtype.org/) out of the box, as long as your Flow version matches the one used in the version of React Native. 150 | 151 | To add a local dependency to the correct Flow version to a Create React Native App project, follow these steps: 152 | 153 | 1. Find the Flow `[version]` at the bottom of the included [.flowconfig](.flowconfig) 154 | 2. Run `npm install --save-dev flow-bin@x.y.z` (or `yarn add --dev flow-bin@x.y.z`), where `x.y.z` is the .flowconfig version number. 155 | 3. Add `"flow": "flow"` to the `scripts` section of your `package.json`. 156 | 4. Add `// @flow` to any files you want to type check (for example, to `App.js`). 157 | 158 | Now you can run `npm run flow` (or `yarn flow`) to check the files for type errors. 159 | You can optionally use a [plugin for your IDE or editor](https://flow.org/en/docs/editors/) for a better integrated experience. 160 | 161 | To learn more about Flow, check out [its documentation](https://flow.org/). 162 | 163 | ## Sharing and Deployment 164 | 165 | Create React Native App does a lot of work to make app setup and development simple and straightforward, but it's very difficult to do the same for deploying to Apple's App Store or Google's Play Store without relying on a hosted service. 166 | 167 | ### Publishing to Expo's React Native Community 168 | 169 | Expo provides free hosting for the JS-only apps created by CRNA, allowing you to share your app through the Expo client app. This requires registration for an Expo account. 170 | 171 | Install the `exp` command-line tool, and run the publish command: 172 | 173 | ``` 174 | $ npm i -g exp 175 | $ exp publish 176 | ``` 177 | 178 | ### Building an Expo "standalone" app 179 | 180 | You can also use a service like [Expo's standalone builds](https://docs.expo.io/versions/latest/guides/building-standalone-apps.html) if you want to get an IPA/APK for distribution without having to build the native code yourself. 181 | 182 | ### Ejecting from Create React Native App 183 | 184 | If you want to build and deploy your app yourself, you'll need to eject from CRNA and use Xcode and Android Studio. 185 | 186 | This is usually as simple as running `npm run eject` in your project, which will walk you through the process. Make sure to install `react-native-cli` and follow the [native code getting started guide for React Native](https://facebook.github.io/react-native/docs/getting-started.html). 187 | 188 | #### Should I Use ExpoKit? 189 | 190 | If you have made use of Expo APIs while working on your project, then those API calls will stop working if you eject to a regular React Native project. If you want to continue using those APIs, you can eject to "React Native + ExpoKit" which will still allow you to build your own native code and continue using the Expo APIs. See the [ejecting guide](https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md) for more details about this option. 191 | 192 | ## Troubleshooting 193 | 194 | ### Networking 195 | 196 | If you're unable to load your app on your phone due to a network timeout or a refused connection, a good first step is to verify that your phone and computer are on the same network and that they can reach each other. Create React Native App needs access to ports 19000 and 19001 so ensure that your network and firewall settings allow access from your device to your computer on both of these ports. 197 | 198 | Try opening a web browser on your phone and opening the URL that the packager script prints, replacing `exp://` with `http://`. So, for example, if underneath the QR code in your terminal you see: 199 | 200 | ``` 201 | exp://192.168.0.1:19000 202 | ``` 203 | 204 | Try opening Safari or Chrome on your phone and loading 205 | 206 | ``` 207 | http://192.168.0.1:19000 208 | ``` 209 | 210 | and 211 | 212 | ``` 213 | http://192.168.0.1:19001 214 | ``` 215 | 216 | If this works, but you're still unable to load your app by scanning the QR code, please open an issue on the [Create React Native App repository](https://github.com/react-community/create-react-native-app) with details about these steps and any other error messages you may have received. 217 | 218 | If you're not able to load the `http` URL in your phone's web browser, try using the tethering/mobile hotspot feature on your phone (beware of data usage, though), connecting your computer to that WiFi network, and restarting the packager. 219 | 220 | ### iOS Simulator won't open 221 | 222 | If you're on a Mac, there are a few errors that users sometimes see when attempting to `npm run ios`: 223 | 224 | * "non-zero exit code: 107" 225 | * "You may need to install Xcode" but it is already installed 226 | * and others 227 | 228 | There are a few steps you may want to take to troubleshoot these kinds of errors: 229 | 230 | 1. Make sure Xcode is installed and open it to accept the license agreement if it prompts you. You can install it from the Mac App Store. 231 | 2. Open Xcode's Preferences, the Locations tab, and make sure that the `Command Line Tools` menu option is set to something. Sometimes when the CLI tools are first installed by Homebrew this option is left blank, which can prevent Apple utilities from finding the simulator. Make sure to re-run `npm/yarn run ios` after doing so. 232 | 3. If that doesn't work, open the Simulator, and under the app menu select `Reset Contents and Settings...`. After that has finished, quit the Simulator, and re-run `npm/yarn run ios`. 233 | 234 | ### QR Code does not scan 235 | 236 | If you're not able to scan the QR code, make sure your phone's camera is focusing correctly, and also make sure that the contrast on the two colors in your terminal is high enough. For example, WebStorm's default themes may [not have enough contrast](https://github.com/react-community/create-react-native-app/issues/49) for terminal QR codes to be scannable with the system barcode scanners that the Expo app uses. 237 | 238 | If this causes problems for you, you may want to try changing your terminal's color theme to have more contrast, or running Create React Native App from a different terminal. You can also manually enter the URL printed by the packager script in the Expo app's search bar to load it manually. 239 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 20 | 21 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 44 | 45 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | false 55 | 56 | false 57 | false 58 | 59 | 60 | true 61 | DEFINITION_ORDER 62 | 63 | 64 | 65 | 66 | 67 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 144 | 145 | 146 | 147 | 148 | 149 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 216 | 217 | 218 | 264 | 265 | 266 | 279 | 280 | 281 | 288 | 291 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 316 | 317 | 318 | 319 | 337 | 344 | 345 | 346 | 347 | 365 | 372 | 373 | 374 | 376 | 377 | 378 | 379 | 1497785461527 380 | 385 | 386 | 387 | 388 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 421 | 422 | 425 | 428 | 429 | 430 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 513 | 514 | 515 | 516 | 517 | 518 | No facets are configured 519 | 520 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 536 | 537 | 538 | 539 | 540 | 541 | 1.8 542 | 543 | 548 | 549 | 550 | 551 | 552 | 553 | BakBak-Relay-RN 554 | 555 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 572 | 573 | 574 | 575 | 576 | 577 | --------------------------------------------------------------------------------