Skip to content

Commit

Permalink
docs(apollo-server): added documentation for apollo server
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Dec 3, 2022
1 parent 968c963 commit 56c4a74
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
[![Semantic Release][semantic-release-img]][semantic-release-url]

Run REST APIs and other web applications using your existing Node.js application framework (NestJS, Deepkit, Express, Koa, Hapi,
Fastify and tRPC), on top of AWS Lambda, Azure, Digital Ocean and many other clouds.
Fastify, tRPC and Apollo Server), on top of AWS Lambda, Azure, Digital Ocean and many other clouds.

This library was a refactored version of [@vendia/serverless-express](https://github.com/vendia/serverless-express), I
create a new way to interact and extend event sources by creating contracts to abstract the integrations between each
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"lambda edge",
"alb",
"lambda",
"apollo server",
"express",
"koa",
"hapi",
Expand Down
6 changes: 6 additions & 0 deletions src/adapters/apollo-server/apollo-server-mutation.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {

/**
* The options for {@link ApolloServerMutationAdapter}
*
* @breadcrumb Adapters / Apollo Server / ApolloServerMutationAdapter
* @public
*/
export type ApolloServerMutationAdapterOptions = {
/**
Expand All @@ -34,6 +37,9 @@ export type ApolloServerMutationAdapterOptions = {

/**
* The adapter that wraps another adapter to force a transformation of the event data as a mutation to Apollo Server be able to handle.
*
* @breadcrumb Adapters / Apollo Server / ApolloServerMutationAdapter
* @public
*/
export class ApolloServerMutationAdapter<
TEvent,
Expand Down
27 changes: 26 additions & 1 deletion src/frameworks/apollo-server/apollo-server.framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,37 @@ import { getDefaultIfUndefined } from '../../core';

//#endregion

/**
* The default context of Apollo Server when you integrate and don't pass any context.
*
* @breadcrumb Frameworks / ApolloServerFramework
* @public
*/
export interface DefaultServerlessApolloServerContext extends BaseContext {
/**
* The request reference
*/
request: IncomingMessage;
/**
* The response reference
*/
response: ServerResponse;
}

/**
* The arguments used to create a Context inside {@link ApolloServerOptions}
*
* @breadcrumb Frameworks / ApolloServerFramework
* @public
*/
export type ApolloServerContextArguments = {
/**
* The request reference
*/
request: IncomingMessage;
/**
* The response reference
*/
response: ServerResponse;
};

Expand All @@ -31,7 +54,7 @@ export interface ApolloServerOptions<TContext extends BaseContext> {
*
* @param options - Default options passed by library
*/
context: (options: ApolloServerContextArguments) => Promise<TContext>;
context?: (options: ApolloServerContextArguments) => Promise<TContext>;
}

/**
Expand Down Expand Up @@ -96,6 +119,8 @@ export class ApolloServerFramework<TContext extends BaseContext>
context,
})
.then(async httpGraphQLResponse => {
// this section was copy and pasted from https://github.com/apollographql/apollo-server/blob/main/packages/server/src/express4/index.ts#L95

for (const [key, value] of httpGraphQLResponse.headers)
response.setHeader(key, value);

Expand Down
2 changes: 2 additions & 0 deletions src/index.doc.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
export * from './@types';
export * from './@types/huawei';
export * from './adapters/apollo-server';
export * from './adapters/aws';
export * from './adapters/azure';
export * from './adapters/digital-ocean';
export * from './adapters/dummy';
export * from './adapters/huawei';
export * from './contracts';
export * from './core';
export * from './frameworks/apollo-server';
export * from './frameworks/body-parser';
export * from './frameworks/cors';
export * from './frameworks/deepkit';
Expand Down
11 changes: 3 additions & 8 deletions test/frameworks/utils-apollo-server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { IncomingMessage, ServerResponse } from 'http';
import { OutgoingHttpHeaders } from 'http2';
import { ApolloServer, BaseContext, HeaderMap } from '@apollo/server';
import {
Expand All @@ -10,6 +9,7 @@ import {
import {
ApolloServerContextArguments,
ApolloServerFramework,
DefaultServerlessApolloServerContext,
} from '../../src/frameworks/apollo-server';
import { JsonBodyParserFramework } from '../../src/frameworks/body-parser';
import { TestRouteBuilderMethods } from './utils';
Expand Down Expand Up @@ -40,12 +40,7 @@ export function runApolloServerTests() {
expectHeaderSet,
] of frameworkTestOptions) {
it(`${method}${queryName}: should forward request and receive response correctly`, async () => {
interface ApolloCustomContext extends BaseContext {
request: IncomingMessage;
response: ServerResponse;
}

const app = new ApolloServer<ApolloCustomContext>({
const app = new ApolloServer<DefaultServerlessApolloServerContext>({
typeDefs: 'type Query { message: String }',
resolvers: {
Query: {
Expand All @@ -72,7 +67,7 @@ export function runApolloServerTests() {
: [undefined, 0];

const framework = new JsonBodyParserFramework(
new ApolloServerFramework<ApolloCustomContext>(),
new ApolloServerFramework<DefaultServerlessApolloServerContext>(),
);

const request = new ServerlessRequest({
Expand Down
Loading

0 comments on commit 56c4a74

Please sign in to comment.