Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jntn/functions-and-graphql
https://github.com/jntn/functions-and-graphql
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/jntn/functions-and-graphql
- Owner: jntn
- Created: 2020-02-07T09:34:12.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-06-02T21:34:35.000Z (over 2 years ago)
- Last Synced: 2023-03-02T15:13:48.160Z (almost 2 years ago)
- Language: HTML
- Size: 67.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Netlify Functions + GraphQL
This repo demonstrates how to use functions for a GraphQL API using `apollo-server-lambda`.
See the graphQL [function code](./functions/graphql.js)
For more information on functions. Checkout [functions.netlify.com](https://functions.netlify.com/) and the [Netlify functions workshop](https://github.com/DavidWells/netlify-functions-workshop#workshop-lessons)
## Setup & Deployment
### Easy mode:
Simply click the deploy button:
### Manual mode:
Follow the steps below to set this up via the [`netlify-cli`](https://cli.netlify.com/)
1. **Fork this repo**
Fork this repo and clone it down to your local machine
```bash
git clone repoURL
```2. **Create this site in Netlify**
Open your terminal and run the following command:
```bash
netlify init
```Choose "create & configure a new site", then add a site name or hit enter for one to be generated for you.
3. **Install our graphQL dependencies**
Change directories into our functions folder and create new package.json
```bash
cd functions && npm init -y
```Now install the `apollo-server-lambda` npm package
```bash
npm install apollo-server-lambda
```4. **Require the graphQL dependencies in your function**
In `functions/graphql.js`, require 'apollo-server-lambda'
5. **Define your GraphQL types**
In `functions/graphql.js`, define your graphQL types
6. **Define your GraphQL resolvers**
In `functions/graphql.js`, define your graphQL resolvers
7. **Create a new `ApolloServer`**
In `functions/graphql.js`, create a new `ApolloServer` and pass it your typeDefs and resolves
8. **Export the Lambda compatible ApolloServer**
In `functions/graphql.js`, turn your server into a lambda compatible function signature
```js
server.createHandler()
```Then export the handler
9. **Deploy the site**
Open your terminal and run the following command:
```bash
netlify deploy -p
```Open the frontend and test your new graphQL endpoint
```
netlify open:site
```10. **You did it! 🎉**
You should see a site like [https://graphql-functions.netlify.com/](https://graphql-functions.netlify.com/) where you can explore your graphQL schema.
## Additional resources
- [The Fullstack Tutorial for GraphQL](https://www.howtographql.com/)