Skip to content

Commit 3f33e84

Browse files
hsavit1kettanaito
authored andcommitted
add react native project code
1 parent d9ea988 commit 3f33e84

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+13747
-76
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
[android]
3+
target = Google Inc.:Google APIs:23
4+
5+
[maven_repositories]
6+
central = https://repo1.maven.org/maven2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
root: true,
3+
extends: '@react-native-community',
4+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pbxproj -text
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
24+
# Android/IntelliJ
25+
#
26+
build/
27+
.idea
28+
.gradle
29+
local.properties
30+
*.iml
31+
32+
# node.js
33+
#
34+
node_modules/
35+
npm-debug.log
36+
yarn-error.log
37+
38+
# BUCK
39+
buck-out/
40+
\.buckd/
41+
*.keystore
42+
!debug.keystore
43+
44+
# fastlane
45+
#
46+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
47+
# screenshots whenever they are needed.
48+
# For more information about the recommended setup visit:
49+
# https://docs.fastlane.tools/best-practices/source-control/
50+
51+
*/fastlane/report.xml
52+
*/fastlane/Preview.html
53+
*/fastlane/screenshots
54+
55+
# Bundle artifact
56+
*.jsbundle
57+
58+
# CocoaPods
59+
/ios/Pods/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import React from 'react'
2+
import {
3+
SafeAreaView,
4+
StyleSheet,
5+
View,
6+
Text,
7+
StatusBar,
8+
FlatList,
9+
ActivityIndicator,
10+
} from 'react-native'
11+
import { Header } from 'react-native/Libraries/NewAppScreen'
12+
import { ApolloProvider, gql, useQuery } from '@apollo/client'
13+
import client from './client'
14+
15+
const GET_CHARACTERS = gql`
16+
query GetCharacters {
17+
characters {
18+
results {
19+
id
20+
name
21+
}
22+
}
23+
}
24+
`
25+
26+
export const App = () => (
27+
<ApolloProvider client={client}>
28+
<MyRootComponent />
29+
</ApolloProvider>
30+
)
31+
32+
const Item = ({ title }) => (
33+
<View style={styles.item}>
34+
<Text style={styles.title}>{title}</Text>
35+
</View>
36+
)
37+
38+
export const MyRootComponent = () => {
39+
const { data, loading, error } = useQuery(GET_CHARACTERS)
40+
41+
const DATA = data?.characters?.results
42+
43+
const renderItem = ({ item }) => {
44+
return <Item title={item.name} />
45+
}
46+
47+
return (
48+
<>
49+
<StatusBar barStyle="dark-content" />
50+
<SafeAreaView style={styles.container}>
51+
<Text style={styles.sectionTitle}>Rick and morty MSW demo</Text>
52+
53+
<Header />
54+
55+
{loading && <ActivityIndicator testID="loading" />}
56+
57+
{error && <Text testID="error">{`${error}`}</Text>}
58+
59+
{!loading && !error && DATA?.length > 0 && (
60+
<FlatList
61+
testID="list"
62+
data={DATA}
63+
renderItem={renderItem}
64+
keyExtractor={(item) => item.id}
65+
/>
66+
)}
67+
</SafeAreaView>
68+
</>
69+
)
70+
}
71+
72+
const styles = StyleSheet.create({
73+
sectionTitle: {
74+
fontSize: 24,
75+
fontWeight: '600',
76+
color: 'black',
77+
marginBottom: 40,
78+
},
79+
container: {
80+
flex: 1,
81+
marginTop: StatusBar.currentHeight || 0,
82+
backgroundColor: 'white',
83+
},
84+
item: {
85+
backgroundColor: '#f9c2ff',
86+
padding: 20,
87+
marginVertical: 8,
88+
marginHorizontal: 16,
89+
},
90+
title: {
91+
fontSize: 32,
92+
},
93+
})
94+
95+
export default App
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# React Native (GraphQL)
2+
3+
This repository illustrates how to use [Mock Service Worker](https://github.com/mswjs/msw) to mock a GraphQL server for development and testing in a React Native project.
4+
5+
## Technologies
6+
7+
- [**React Native**](https://reactnative.dev)
8+
- [React Testing Library](https://github.com/testing-library/react-testing-library) for testing assertions;
9+
10+
## Getting started
11+
12+
```bash
13+
$ git clone https://github.com/mswjs/examples.git
14+
$ cd examples
15+
$ yarn
16+
$ cd graphql-react-native-apollo
17+
```
18+
19+
## Running locally
20+
21+
```bash
22+
$ yarn start
23+
```
24+
25+
### Android
26+
27+
```bash
28+
$ yarn android
29+
```
30+
31+
### iOS
32+
33+
```bash
34+
$ yarn ios
35+
```
36+
37+
## Tests
38+
39+
```bash
40+
$ yarn test
41+
```
42+
43+
## Key points
44+
45+
- [`mocks/handlers.js`](mocks/handlers.js) describes request handlers to use.
46+
47+
### React Native
48+
49+
- [`mocks/native.js`](mocks/native.js) enables request interception in React Native runtime;
50+
- [`index.js`](index.js) conditionally enables mocking in `development` environment.
51+
52+
### NodeJS
53+
54+
- [`mocks/server.js`](mocks/server.js) enables requests interceptions in NodeJS (i.e. for tests with jest);
55+
- [`jest.setup.js`](jest.setup.js) configures test runner to use API mocking in tests.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# To learn about Buck see [Docs](https://buckbuild.com/).
2+
# To run your application with Buck:
3+
# - install Buck
4+
# - `npm start` - to start the packager
5+
# - `cd android`
6+
# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
7+
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
8+
# - `buck install -r android/app` - compile, install and run application
9+
#
10+
11+
load(":build_defs.bzl", "create_aar_targets", "create_jar_targets")
12+
13+
lib_deps = []
14+
15+
create_aar_targets(glob(["libs/*.aar"]))
16+
17+
create_jar_targets(glob(["libs/*.jar"]))
18+
19+
android_library(
20+
name = "all-libs",
21+
exported_deps = lib_deps,
22+
)
23+
24+
android_library(
25+
name = "app-code",
26+
srcs = glob([
27+
"src/main/java/**/*.java",
28+
]),
29+
deps = [
30+
":all-libs",
31+
":build_config",
32+
":res",
33+
],
34+
)
35+
36+
android_build_config(
37+
name = "build_config",
38+
package = "com.mswdemo",
39+
)
40+
41+
android_resource(
42+
name = "res",
43+
package = "com.mswdemo",
44+
res = "src/main/res",
45+
)
46+
47+
android_binary(
48+
name = "app",
49+
keystore = "//android/keystores:debug",
50+
manifest = "src/main/AndroidManifest.xml",
51+
package_type = "debug",
52+
deps = [
53+
":app-code",
54+
],
55+
)

0 commit comments

Comments
 (0)