This example is using GraphQL to store, retrieve and manipulate books and authors data.
The front end is using Reactjs and Apollo which will be able to make queries to the graphql server and retrieve data back into the browser.
The back end is using GraphQL server on Nodejs using Express to describe how the graph looks (types of data on the graph, and the relations between those types), and setup different entry points into the graph. This is hooked up with two different types of data storage:
- Flat javascript local array.
- Mongodb online database instance.
Tip 1: Use Graphiql tool from the browser to simulate making queries from the front end to the GraphQL server.
Tip 2: You can change the data source for the app by editing the variable [schema] in the file [./server/app.js] and use either local or remote data source, default is local.
You can install GraphQL-Client-Server-Sample-Code as follows:
cd folder/to/clone-into/
git clone https://github.com/mostafaaminflakes/GraphQL-Client-Server-Sample-Code.git
Make sure to install the following dependencies:
Server
- express
- graphql
- express-graphql
- lodash
- mongoose
Client
- react
- apollo-boost
- react-apollo
- graphql
- lodash
Tip: You may run [npm install] from inside both client and server folders to install the required dependencies.
You need two instances of cmd:
1. To run the server:
cd path/to/server/folder/
node app
Then open your browser at [localhost:4000/graphql]
2. To run the client:
cd path/to/client/folder/
npm start
Then open your browser at [localhost:3000]