Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure functions typescript #2487

Merged
merged 11 commits into from
Apr 5, 2019
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- New plugin package `apollo-server-plugin-response-cache` implementing a full query response cache based on `apollo-cache-control` hints. The implementation added a few hooks and context fields; see the PR for details. There is a slight change to `cacheControl` object: previously, `cacheControl.stripFormattedExtensions` defaulted to false if you did not provide a `cacheControl` option object, but defaulted to true if you provided (eg) `cacheControl: {defaultMaxAge: 10}`. Now `stripFormattedExtensions` defaults to false unless explicitly provided as `true`, or if you use the legacy boolean `cacheControl: true`. [PR #2437](https://github.com/apollographql/apollo-server/pull/2437)
- Allow `GraphQLRequestListener` callbacks in plugins to depend on `this`. [PR #2470](https://github.com/apollographql/apollo-server/pull/2470)
- Move shared TypeScript utility types `WithRequired` and `ValueOrPromise` into `apollo-server-env`. [PR #2415](https://github.com/apollographql/apollo-server/pull/2415) [PR #2417](https://github.com/apollographql/apollo-server/pull/2417)
- Support `@azure/functions` to enable Apollo Server [Typescript development in Azure Functions](https://azure.microsoft.com/en-us/blog/improving-the-typescript-support-in-azure-functions/).

### v2.4.8

Expand Down
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"graphql-extensions": "file:packages/graphql-extensions"
},
"devDependencies": {
"@azure/functions": "^1.0.2-beta2",
"@types/async-retry": "1.2.1",
"@types/aws-lambda": "8.10.23",
"@types/body-parser": "1.17.0",
Expand Down Expand Up @@ -93,6 +94,7 @@
"apollo-link": "1.2.11",
"apollo-link-http": "1.5.14",
"apollo-link-persisted-queries": "0.2.2",
"azure-functions-ts-essentials": "^1.3.2",
michael-watson marked this conversation as resolved.
Show resolved Hide resolved
"body-parser": "1.18.3",
"codecov": "3.2.0",
"connect": "3.6.6",
Expand Down
19 changes: 8 additions & 11 deletions packages/apollo-server-azure-functions/src/ApolloServer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
HttpContext,
FunctionRequest,
FunctionResponse,
} from './azureFunctions';
import { Context, HttpRequest } from '@azure/functions';
import { HttpResponse } from 'azure-functions-ts-essentials';
import { ApolloServerBase } from 'apollo-server-core';
import { GraphQLOptions, Config } from 'apollo-server-core';
import {
Expand Down Expand Up @@ -41,8 +38,8 @@ export class ApolloServer extends ApolloServerBase {
// provides typings for the integration specific behavior, ideally this would
// be propagated with a generic to the super class
createGraphQLServerOptions(
request: FunctionRequest,
context: HttpContext,
request: HttpRequest,
context: Context,
): Promise<GraphQLOptions> {
return super.graphQLServerOptions({ request, context });
}
Expand All @@ -53,7 +50,7 @@ export class ApolloServer extends ApolloServerBase {
// the GraphQLServerOptions function which is called before each request.
const promiseWillStart = this.willStart();

const corsHeaders: FunctionResponse['headers'] = {};
const corsHeaders: HttpResponse['headers'] = {};

if (cors) {
if (cors.methods) {
Expand Down Expand Up @@ -92,7 +89,7 @@ export class ApolloServer extends ApolloServerBase {
}
}

return (context: HttpContext, req: FunctionRequest) => {
return (context: Context, req: HttpRequest) => {
if (cors && cors.origin) {
if (typeof cors.origin === 'string') {
corsHeaders['Access-Control-Allow-Origin'] = cors.origin;
Expand Down Expand Up @@ -125,7 +122,7 @@ export class ApolloServer extends ApolloServerBase {
if (this.playgroundOptions && req.method === 'GET') {
const acceptHeader = req.headers['Accept'] || req.headers['accept'];
if (acceptHeader && acceptHeader.includes('text/html')) {
const path = req.originalUrl || '/';
const path = req.url || '/';

const playgroundRenderPageOptions: PlaygroundRenderPageOptions = {
endpoint: path,
Expand All @@ -144,7 +141,7 @@ export class ApolloServer extends ApolloServerBase {
}
}

const callbackFilter = (error?: any, output?: FunctionResponse) => {
const callbackFilter = (error?: any, output?: HttpResponse) => {
context.done(
error,
output && {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
HttpContext,
FunctionRequest,
FunctionResponse,
} from './azureFunctions';
import { Context, HttpRequest, AzureFunction } from '@azure/functions';
import {
GraphQLOptions,
HttpQueryError,
Expand All @@ -11,22 +7,12 @@ import {
import { Headers, ValueOrPromise } from 'apollo-server-env';

export interface AzureFunctionGraphQLOptionsFunction {
(request: FunctionRequest, context: HttpContext): ValueOrPromise<
GraphQLOptions
>;
}

export interface AzureFunctionHandler {
(
context: HttpContext,
request: FunctionRequest,
callback: (err?: any, output?: FunctionResponse) => void,
): void;
(request: HttpRequest, context: Context): ValueOrPromise<GraphQLOptions>;
}

export function graphqlAzureFunction(
options: GraphQLOptions | AzureFunctionGraphQLOptionsFunction,
): AzureFunctionHandler {
): AzureFunction {
if (!options) {
throw new Error('Apollo Server requires options.');
}
Expand All @@ -37,11 +23,7 @@ export function graphqlAzureFunction(
);
}

const graphqlHandler: AzureFunctionHandler = (
context,
request,
callback,
): void => {
const graphqlHandler: AzureFunction = (context, request, callback): void => {
if (request.method === 'POST' && !request.body) {
callback(null, {
body: 'POST body missing.',
Expand All @@ -57,7 +39,7 @@ export function graphqlAzureFunction(
? request.body
: request.query,
request: {
url: request.originalUrl,
url: request.url,
method: request.method,
headers: new Headers(request.headers),
},
Expand Down
153 changes: 0 additions & 153 deletions packages/apollo-server-azure-functions/src/azureFunctions.ts

This file was deleted.