Giter VIP home page Giter VIP logo

yc-serverless-graphql-subscriptions's Introduction

Yandex Cloud Serverless GraphQL Subscriptions

Example on how to implement a basic GraphQL subscriptions using Yandex Cloud Serverless ecosystem

Setup

Resources required:

  • YDB
  • 3 Cloud functions
  • Api Gateway

Infrastructure

As of now WebSocket and YDB features are not supported by YC's terraform or serverless, so we are to create resources and execute migrations manually.

  • Create a folder
  • Create a service-account. For simplicity give this account admin role to the folder. In production the role should be more granular
  • Create graphql-websocket-connect function
  • Create graphql-websocket-message function
  • Create graphql-websocket-disconnect function
  • Create a YDB database in a serverless mode
  • In the database console execute SQL queries from /src/migrations/ consequently
  • Create Api Gateway with config similar to this:
openapi: 3.0.0
info:
  title: Sample API
  version: 1.0.0
paths:
  /:
    x-yc-apigateway-websocket-connect:
      x-yc-apigateway-integration:
        type: cloud_functions
        function_id: <graphql-websocket-connect id>
        tag: $latest
        service_account_id: <service-account id>
    x-yc-apigateway-websocket-message:
      x-yc-apigateway-integration:
        type: cloud_functions
        function_id: <graphql-websocket-message id>
        tag: $latest
        service_account_id: <service-account id>
    x-yc-apigateway-websocket-disconnect:
      x-yc-apigateway-integration:
        type: cloud_functions
        function_id: <graphql-websocket-disconnect id>
        tag: $latest
        service_account_id: <service-account id>

Note that function_ids and service_account_id should be replaced with corresponding data. As long as you keep the ids you can specify any name for the function. In production this should be configured with terraform and CI scripts

Development

  • Install packages using npm ci
  • Create service account with at least functions.editor role
  • Create and save authorized key for this account
  • Create and fill .env file in the repository root accordingly to example.env
  • Execute npm dev

This is gonna upload the functions to the cloud and start watch mode for development

Testing

https://studio.apollographql.com/sandbox/explorer can be used for GraphQL query\subscription testing after deployment

Code generation and tools

This project uses several tools some of which might be considered unorthodox:

graphql-codegen

Production solution to generate typescript and resolver definitions from GraphQL Schema

esbuild

One of the fastest Typescript to Javascript compilers

ydb-codegen

WIP project to simplify working with Yandex Database

serverless-esbuild

Plugin for esbuild which makes development process faster

yc-serverless-graphql-subscriptions's People

Contributors

davyjohnes avatar esseswann avatar kvikuz avatar nettworker avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

esseswann

yc-serverless-graphql-subscriptions's Issues

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.