Looking to incorporate some checks before executing the apollo handler function, I attempted to wrap it in an async function. However, when exporting the function as async, it consistently returns an empty response.
functions.json
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
],
"scriptFile": "../dist/graphql/index.js"
}
The set up:
import { buildSchema } from 'type-graphql';
import { ApolloServer } from 'apollo-server-azure-functions';
import { Context, HttpRequest } from '@azure/functions';
import { resolvers } from '../src/graphql';
import { authChecker } from '../src/auth';
const schema = buildSchema({
resolvers,
authChecker,
});
const server = new ApolloServer({
schema,
context: ({ context }) => context, // directly use azure Context as Apollo context,
});
const handler = server.createHandler();
This setup functions correctly
export default (context: Context, request: HttpRequest) => {
handler(context, request);
};
However, adding async behavior leads to an empty response
export default async (context: Context, request: HttpRequest) => {
// do async stuff: await ...
handler(context, request);
};