Giter Site home page Giter Site logo

functions-and-graphql's Introduction

Netlify Functions + GraphQL

This repo demonstrates how to use functions for a GraphQL API using apollo-server-lambda.

See the graphQL function code

For more information on functions. Checkout functions.netlify.com and the Netlify functions workshop

Setup & Deployment

Easy mode:

Simply click the deploy button:

Manual mode:

Follow the steps below to set this up via the netlify-cli

  1. Fork this repo

    Fork this repo and clone it down to your local machine

    git clone repoURL
  2. Create this site in Netlify

    Open your terminal and run the following command:

    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

    cd functions && npm init -y

    Now install the apollo-server-lambda npm package

    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

    server.createHandler()

    Then export the handler

  9. Deploy the site

    Open your terminal and run the following command:

    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/ where you can explore your graphQL schema.

Additional resources

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.