The main porpuse of this repo is be a sample of how to integrate Apollo Server + GraphQL + Serverless Architecture. For this we have created a search API thought a schema like following:
To summarize we have 3 entities: User, Company and Contacts. So, if I wish retrieve all the contacts of a specific company, how could I do it? This question will be answered by this code.
To understand the concepts and code implemented in this repo it's necessary a basic knowledge of GraphQL, Serverless Architecture and Node.js programming language.
After clone this repo in your computer, go to project folder and install dependencies using the following command:
npm i
After all dependencies have installed you can run the project throught the command:
npm run offline
If everything was fine you could see a screen like this:
This implementation was based on the post Running a scalable & reliable GraphQL endpoint with Serverless.
Basically, the project contains two handlers, as you can see at serverless.yml file:
graphql
: whose implementation is in src/handler.js file, more specifically at line 11. This handler is responsible to process requests throught GraphQL using apollo-server-lambda implementation. In other words is the Backend API of our project.graphiql
: whose implementation is in src/handler.js file, more specifically at line 25. This handler returns a GraphQL Client implementation called graphiql. Where you can write your queries and see the results.
Other important files are:
- graphql: The graphql folder contains the graphql schema used for this project. In this folder you will find all schema's types, resolvers and queries.
- schema.js: Where we define the GraphQL types, queries, mutations and subscriptions, which makes up the GraphQL Schema.
- resolvers.js: The implementation of GraphQL resolvers based on types and queries defined at
schema.js
. - types.js: Just an array of types which will by used at
schema.js
.
- src/core: The core folder contains the code to integrate with data layer. We have used DynamoDB to persist data.
- dynamodb/seed-data: The seed-data folder contains sample data used on offline mode. See
serverless-dynamodb-local
for more information.
Just open the link http://localhost:3000/graphiql
in your browser.
- Compares Apollo Engine and AppSync to manage cache and metrics about the GraphQL API
- Reimplement this project using some GraphDB
- Amazon Neptune: until now (04/19/2018) neptune is only available for whitelisted users and there is no integration from Lambda functions. To request a preview for Neptune click here.
- Neo4j: It's a good option, but, AWS there is no a managed service for neo4j. So you have to install and mantain it in a EC2 instance.
To run neo4j using docker run the following command:
npm run neo4j:start
- neo4j/seed-data.js: the porpuse of this file is to create data on neo4j docker instance.
We are using jest for testing.
npm run test
npm run coverage
npm run generate-docs
After see generated site in ./docs/index.html.
First of all you need to configure your AWS credentials:
sls config credentials --provider aws --key <your_aws_access_key> --secret <your_aws_secret_key>
After that:
npm run deploy