Azure 函数的阿波罗服务器集成
导言
阿波罗服务器集成,用于Azure函数.
这是一个简单的软件包,允许您将阿波罗服务器集成到Azure函数应用程序中.
所需资源
- 节点.js v22 或稍后时间
- Azure 函数 v4 或稍后时间
- 图QL.js v16 或稍后时间
- 阿波罗服务器 v4 或稍后时间
安装
npm install @as-integrations/azure-functions @apollo/server graphql @azure/functions
使用量
- 设置一个 带有类型脚本的 Azure 函数 (或 Java 脚本按正常情况计算.
- 创建新 HTTP 触发器
- 更新
index.ts用于使用阿波罗集成:
页:1
import { ApolloServer } from '@apollo/server';
import { startServerAndCreateHandler } from '@as-integrations/azure-functions';
// The GraphQL schema
const typeDefs = `#graphql
type Query {
hello: String
}
`;
// A map of functions which return data for the schema.
const resolvers = {
Query: {
hello: () => 'world',
},
};
// Set up Apollo Server
const server = new ApolloServer({
typeDefs,
resolvers,
});
export default startServerAndCreateHandler(server);
页:1
import { ApolloServer } from '@apollo/server';
import { v4 } from '@as-integrations/azure-functions';
// The GraphQL schema
const typeDefs = `#graphql
type Query {
hello: String
}
`;
// A map of functions which return data for the schema.
const resolvers = {
Query: {
hello: () => 'world',
},
};
// Set up Apollo Server
const server = new ApolloServer({
typeDefs,
resolvers,
});
app.http('graphql', {
handler: v4.startServerAndCreateHandler(server),
});
- 更新
function.jsonHTTP 输出绑定使用$return作为名称, 随着整合从函数处理器返回 (仅v3)数字 :
{
"type": "http",
"direction": "out",
"name": "$return"
}
- 运行 Azure 函数应用并导航到函数端点