Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akshayymahajan/netlify-functions-mongodb-graphql
A Netlify functions template for Apollo Server GraphQL API with MongoDB.
https://github.com/akshayymahajan/netlify-functions-mongodb-graphql
Last synced: 16 days ago
JSON representation
A Netlify functions template for Apollo Server GraphQL API with MongoDB.
- Host: GitHub
- URL: https://github.com/akshayymahajan/netlify-functions-mongodb-graphql
- Owner: akshayymahajan
- Created: 2019-06-26T15:51:04.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-06-25T06:12:36.000Z (over 2 years ago)
- Last Synced: 2024-10-30T12:55:34.459Z (17 days ago)
- Language: JavaScript
- Homepage:
- Size: 98.6 KB
- Stars: 27
- Watchers: 0
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Netlify Functions: MongoDB + GraphQL
A Netlify functions template for Apollo Server GraphQL API with MongoDB.
## Add to Existing Project
cd into your project directory and run `netlify functions:create` to create a new function.select `*** Clone template from Github URL ***` from the list of templates.
In the URL field enter `https://github.com/akshayymahajan/netlify-functions-mongodb-graphql/tree/master/functions/mongodb-graphql`
Netlify CLI will download the function and install all the dependencies in your project.
## Local Development
Clone the repository and run the following commands to install all the dependencies:
```
cd netlify-functions-mongodb-graphql/functions/mongodb-graphql
npm i
```### Setup Environment Variables in your Netlify Site Settings
Login to your [Netlify](https://app.netlify.com) account. Go to and select your site, then go to:
```Site Settings > Build & Deploy > Environment```Then click on **Edit Variables** and setup the following variables:
```
DB_URI =
DB_NAME =
```### typedefs.js
Edit ```typedefs.js``` according to your GraphQL schema.
```
type Todo {
id: ID!
title: String!
completed: Boolean!
}type Query {
allTodos: [Todo]
}
```### resolvers.js
Edit ```resolvers.js``` to return the resolvers for your schema.
```
{
Query: {
allTodos: async () =>
await db
.collection("todos")
.find()
.toArray()
}
}
```### Run Dev Server
Open a terminal and run ```netlify dev``` to start the dev server. Netlify Dev will automatically fetch and inject the environment variables from your Netlify Site Settings and start a local dev sever on http://localhost:8888. To access GraphQL Playground, visit http://localhost:8888/.netlify/functions/mongodb-graphql in a browser window.