All Projects → LinbuduLab → apollo-server-midway

LinbuduLab / apollo-server-midway

Licence: MIT license
Apllo-Server integration for Midway & Midway Serverless

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to apollo-server-midway

Midway
🍔 A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade. Works on AWS, Alibaba Cloud, Tencent Cloud and traditional VM/Container. Super easy integrate with React and Vue. 🌈
Stars: ✭ 5,080 (+38976.92%)
Mutual labels:  serverless-framework, midway
mall-by-react
一个react商城客户端和egg服务端
Stars: ✭ 22 (+69.23%)
Mutual labels:  midway
Heighliner
A GraphQL Server for NewSpring Web
Stars: ✭ 13 (+0%)
Mutual labels:  apollo-server
serverless-typescript-starter
A Serverless starter that adds TypeScript, serverless-offline, linting, environment variables, and unit test support.
Stars: ✭ 75 (+476.92%)
Mutual labels:  serverless-framework
cloudwatch-public-metrics
Expose AWS Cloudwatch Metrics as a public HTML page using AWS Lambda and server-side rendering
Stars: ✭ 27 (+107.69%)
Mutual labels:  serverless-framework
event-gateway-workshop
Learn what the Event Gateway is, how it works and build your first event-driven multi-cloud application!
Stars: ✭ 18 (+38.46%)
Mutual labels:  serverless-framework
lambda-sns-dlq-error-handling
Sample project for showing the ability to publish an SNS topic and trigger a function from the topic. Code is structured to create a timeout/crash so the dead letter queue SNS topic gets published, in turn triggering the error handler function.
Stars: ✭ 31 (+138.46%)
Mutual labels:  serverless-framework
serverless-alexa-skills
Manage your Alexa Skills with Serverless Framework
Stars: ✭ 69 (+430.77%)
Mutual labels:  serverless-framework
aws-serverless-swift-api-template
A Serverless REST API template, implemented in Swift with swift-aws-lambda-runtime.
Stars: ✭ 42 (+223.08%)
Mutual labels:  serverless-framework
z
基于 MidwayJS(EggJS) + TypeScript 的多模块应用 [ NodeJS 版 ]
Stars: ✭ 122 (+838.46%)
Mutual labels:  midway
tencent-cam-policy
Easily create an Tencent CAM Policy with Serverless Components
Stars: ✭ 20 (+53.85%)
Mutual labels:  serverless-framework
serverless-scaleway-functions
Plugin for Serverless Framework to allow users to deploy their serverless applications on Scaleway Functions
Stars: ✭ 58 (+346.15%)
Mutual labels:  serverless-framework
triggerflow
Event-based Orchestration of Serverless Workflows
Stars: ✭ 38 (+192.31%)
Mutual labels:  serverless-framework
apollobank
A full stack GraphQL banking application using React, Node & TypeScript.
Stars: ✭ 203 (+1461.54%)
Mutual labels:  apollo-server
apollo-express-ts-server-boilerplate
No description or website provided.
Stars: ✭ 29 (+123.08%)
Mutual labels:  apollo-server
adonis-apollo-server
GraphQL implementation using Apollo Server for Adonis
Stars: ✭ 14 (+7.69%)
Mutual labels:  apollo-server
serverless
BlueNimble is a Hybrid Serverless Platform focusing on developer productivity and application portability. Create and run scalable APIs and applications without coding or by coding less. Focus on application business logic without any knowledge of the underlying microservices architecture.
Stars: ✭ 30 (+130.77%)
Mutual labels:  serverless-framework
graphql-compose-elasticsearch
Graphql App using Node with typescript, KOA framework and Elasticsearch
Stars: ✭ 40 (+207.69%)
Mutual labels:  apollo-server
perseus
An Apollo GraphQL Server & React Client in a Yarn Workspace deployed with Zeit 2.0
Stars: ✭ 35 (+169.23%)
Mutual labels:  apollo-server
tencent-apigateway
Easily provision Tencent API Gateway using Serverless Components
Stars: ✭ 33 (+153.85%)
Mutual labels:  serverless-framework

apollo-server-midway

English | 简体中文

推荐直接阅读 Midway 官方文档部分:GraphQL | Midway

V3 版本见 apollo-server-midway-v3(开发中)

🎉 Announcing V 1.0

现在你可以在 Midway Serverless 中使用 Apollo-Server(V3)TypeGraphQL 了:

  • 支持 Apollo ServerTypeGraphQL 绝大部分在 Serverless 场景下的可用配置
  • 支持 Serverless 应用(通过 Apollo-Server 作为解析器) 与 普通 Node 应用(通过 Apollo-Server 作为中间件,已支持 koa/ Express 版本)
  • 内置开箱即用的插件功能,如 Query ComplexityResolve Time 等,后续还会有更多插件。
  • 集成 Midway ContainerDebug 能力(如在 GraphQL Response 中通过 extensions 字段返回上下文、GraphQL Schema 等信息)
  • 基于 Apollo Server V3,默认禁用 Apollo Sandbox,使用 GraphQL Playground
  • 90+ 单测覆盖率

在开始前,你可以通过 experimental-midway-sls-graphqlsample 来了解大概的使用方式。

详细文档参考:在 Midway(Serverless) 中使用 GraphQL

Quick Start

Apollo-Server + Midway Serverless

在 Serverless 场景中使用 apollo-server-midway

npm install apollo-server-midway graphql type-graphql --save
yarn add apollo-server-midway graphql type-graphql --save
pnpm install apollo-server-midway graphql type-graphql --save

type-graphql 是可选的依赖,如果你已经拥有构建完毕的 GraphQL Schema,可以不使用它。同时,请确保你在 MidwayJS 项目中使用,因为包括 @midwayjs/core 以及 @midwayjs/decorator 等的一批依赖被标记为 peerDependencies

import {
  Provide,
  Inject,
  ServerlessTrigger,
  ServerlessFunction,
  ServerlessTriggerType,
  App,
} from "@midwayjs/decorator";
import { Context, IMidwayFaaSApplication } from "@midwayjs/faas";
import { createApolloServerHandler } from "apollo-server-midway";
import { SampleResolver } from "../resolvers/sample.resolver";
import { DogResolver } from "../resolvers/dog.resolver";
import path from "path";

const apolloHandlerFuncName = "apollo-handler";

const APOLLO_SERVER_MIDWAY_PATH = "/apollo";

@Provide()
export class HelloHTTPService {
  @Inject()
  ctx: Context;

  @App()
  app: IMidwayFaaSApplication;

  @ServerlessFunction({
    functionName: apolloHandlerFuncName,
  })
  @ServerlessTrigger(ServerlessTriggerType.HTTP, {
    path: APOLLO_SERVER_MIDWAY_PATH,
    method: "get",
  })
  @ServerlessTrigger(ServerlessTriggerType.HTTP, {
    path: APOLLO_SERVER_MIDWAY_PATH,
    method: "post",
  })
  async apolloHandler() {
    return await createApolloServerHandler({
      path: "/",
      app: this.app,
      context: this.ctx,
      schema: {
        resolvers: [SampleResolver, DogResolver],
      },
    });
  }
}

在上面的示例中,函数 apollo-handler 将被部署在 SLS_DOMAIN/SERVICE/apollo-handler 下,你可以通过 SLS_DOMAIN/SERVICE/apollo-handler/ 访问(注意 /)。

Apollo-Server + Midway Node Application

npm install apollo-server-midway graphql type-graphql @midwayjs/koa --save
yarn add apollo-server-midway graphql type-graphql @midwayjs/koa --save
pnpm install apollo-server-midway graphql type-graphql @midwayjs/koa --save

@midwayjs/koa 替换为你应用对应的框架,目前仅有 Koa / Express 支持。

你可以查看 koa-app-sample / express-app-sample 获得更多信息。

在普通 Node 应用中,更推荐通过自己定义 GraphQL 中间件的方式来接入 GraphQL Server,因为其成本是非常低的,同时相比框架的黑盒,你可以更容易的做定制。Apollo-Server-Midway同样会更侧重 Serverless 能力相关,因为对于花样百出的 Node 应用定制需求,我们无法做到满足每一个使用者。关于如何定制,请参考 文档-定制 GraphQL 中间件

// config.default.ts
import { SampleResolver } from "../resolvers/sample.resolver";
import { CreateGraphQLMiddlewareOption } from "apollo-server-midway";

export const graphql: CreateGraphQLMiddlewareOption = {
  schema: {
    resolvers: [SampleResolver],
  },
};

// configuration.ts
import { Configuration, App } from "@midwayjs/decorator";
import { ILifeCycle } from "@midwayjs/core";
import { IMidwayKoaApplication } from "@midwayjs/koa";
import * as GraphQL from "apollo-server-midway";

@Configuration({
  imports: [GraphQL],
  importConfigs: ["./config"],
})
export class ContainerConfiguration implements ILifeCycle {
  @App()
  app: IMidwayKoaApplication;

  async onReady(): Promise<void> {
    this.app.use(
      // Express 下的命名空间:graphql:GraphQLExpressMiddleware
      await this.app.generateMiddleware("graphql:GraphQLKoaMiddleware")
    );
  }
}

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].