🚀 Basic starter code for a mobile app based on React Native, GraphQL & Apollo Client.
- Frontend
- React Native: JavaScript framework for building native mobile apps with React
- Expo: Free and open source toolchain build around React Native to help you build native iOS and Android projects using JavaScript and React.
- Apollo Client: Fully-featured, production ready caching GraphQL client
- Backend
- Prisma: Turns your database into a GraphQL API
graphql-yoga: Fully-featured GraphQL server with focus on easy setup, performance & great developer experienceprisma-binding: GraphQL binding for Prisma services
You need to have the following things installed:
- Expo
- Node 8+
- GraphQL CLI:
npm i -g graphql-cli
# 1. Bootstrap GraphQL server in directory `my-app`, based on `react-native-basic` boilerplate
graphql create my-app --boilerplate react-native-basic
# 2. When prompted, choose the Prisma cluster you want to deploy to
# e.g. prisma-eu1 or prisma-us1 to deploy to a public cluster (recommended)
# or locally (requires Docker)
# 3. Navigate into the `server` directory of the new project
cd my-app/server
# 4. Start the server
yarn start # the server is now running on http://localhost:4000
# 5. Open a new tab in the terminal and navigate back into my-app
# then run the app
cd ..
yarn start
# 6. Open the app in a simulator or device of your choice
# open using the Expo app on your phone (does not work when server is deployed locally)If you'd rather not use graphql-cli, follow these instructions:
# 1. yarn startstarts GraphQL server onhttp://localhost:4000(only allows access to the application)yarn devstarts GraphQL server and opens the GraphQL Playground for theprojectsdefined in.graphqlconfig.ymlyarn playgroundopens the GraphQL Playground for theprojectsdefined in.graphqlconfig.ymlyarn prisma <subcommand>access to local version of Prisma CLI (e.g.yarn prisma deploy)
yarn startyarn run iosopens the iOS Simulatoryarn run androidopens the Android emulator
.graphqlconfig.ymlGraphQL configuration file containing the endpoints and schema configuration. Used by thegraphql-cliand the GraphQL Playground. Seegraphql-configfor more information.graphcool.yml: The root configuration file for your database service (documentation).
database/datamodel.graphqlcontains the data model that you define for the project (written in SDL).database/schema.generated.graphqldefines the database schema. It contains the definition of the CRUD API for the types in your data model and is generated based on yourdatamodel.graphql. You should never edit this file manually, but introduce changes only by alteringdatamodel.graphqland rungraphcool deploy.
src/schema.graphqldefines your application schema. It contains the GraphQL API that you want to expose to your client applications.src/index.jsis the entry point of your server, pulling everything together and starting theGraphQLServerfromgraphql-yoga.
Access to the Graphcool API is secured by a secret. This also applies to the introspection query. Using the latest version of GraphQL Playground, the Authorization header should automatically be setup with a proper JWT signing the secret. If that's not the case, you can follow these steps to access your API:
- Visit http://jwtbuilder.jamiekurtz.com/
- Replace the
Keyat the bottom of the page with yoursecretfrom thegraphcool.yml - Click
Create signed JWTand copy the obtained token - Now, to access the schema, use the
Authorization: Bearer <token>header, or in the GraphQL Playground set it as JSON:{ "Authorization": "Bearer <token>" } - Reload the schema in the Playground (the refresh-button is located right next to the URL of the server)
Note: Currently, no content of the signed JWT is verified by the database! This will be implemented according to this proposal at a later stage.
Your feedback is very helpful, please share your opinion and thoughts! If you have any questions, join the #graphql-boilerplate channel on our Slack.