Exception: TypeError: graphqlAzureFunctions is not a function when using Apollo for Azure Functions
Exception: TypeError: graphqlAzureFunctions is not a function when using Apollo for Azure Functions
我的package.json:
{
"name": "azurejs",
"version": "0.1.0",
"private": true,
"dependencies": {
"apollo-server-azure-functions": "^2.2.6",
"graphql": "^14.0.2",
"graphql-tools": "^4.0.3"
},
"scripts": {},
"devDependencies": {}
}
直接使用apollo例子中的代码:
const { graphqlAzureFunctions } = require('apollo-server-azure-functions');
const { makeExecutableSchema } = require('graphql-tools');
const typeDefs = `
type Random {
id: Int!
rand: String
}
type Query {
rands: [Random]
rand(id: Int!): Random
}
`;
const rands = [{ id: 1, rand: 'random' }, { id: 2, rand: 'modnar' }];
const resolvers = {
Query: {
rands: () => rands,
rand: (_, { id }) => rands.find(rand => rand.id === id),
},
};
const schema = makeExecutableSchema({
typeDefs,
resolvers,
});
module.exports = function run(context, request) {
graphqlAzureFunctions({ schema })(context, request);
};
https://www.apollographql.com/docs/apollo-server/v1/servers/azure-functions.html
如果我导航到端点,我会收到错误 'graphqlAzureFunctions is not a function',我搜索了那个,但确实找不到该函数。
您在使用 v1 教程中的代码时安装了 v2 apollo-server 包。
关注 v2 tutorial,安装 apollo-server-azure-functions@alpha
,graphql
,我们可能会继续使用 v2 代码。
const { gql, ApolloServer } = require("apollo-server-azure-functions");
// Construct a schema, using GraphQL schema language
const typeDefs = gql`
type Query {
hello: String
}
`;
// A map of functions which return data for the schema.
const resolvers = {
Query: {
hello: () => "world"
}
};
const server = new ApolloServer({ typeDefs, resolvers });
module.exports = server.createHandler();
请注意,在function.json
中,我们需要"name": "$return"
,而模板默认使用"name": "res"
。
{
"disabled": false,
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
我的package.json:
{
"name": "azurejs",
"version": "0.1.0",
"private": true,
"dependencies": {
"apollo-server-azure-functions": "^2.2.6",
"graphql": "^14.0.2",
"graphql-tools": "^4.0.3"
},
"scripts": {},
"devDependencies": {}
}
直接使用apollo例子中的代码:
const { graphqlAzureFunctions } = require('apollo-server-azure-functions');
const { makeExecutableSchema } = require('graphql-tools');
const typeDefs = `
type Random {
id: Int!
rand: String
}
type Query {
rands: [Random]
rand(id: Int!): Random
}
`;
const rands = [{ id: 1, rand: 'random' }, { id: 2, rand: 'modnar' }];
const resolvers = {
Query: {
rands: () => rands,
rand: (_, { id }) => rands.find(rand => rand.id === id),
},
};
const schema = makeExecutableSchema({
typeDefs,
resolvers,
});
module.exports = function run(context, request) {
graphqlAzureFunctions({ schema })(context, request);
};
https://www.apollographql.com/docs/apollo-server/v1/servers/azure-functions.html
如果我导航到端点,我会收到错误 'graphqlAzureFunctions is not a function',我搜索了那个,但确实找不到该函数。
您在使用 v1 教程中的代码时安装了 v2 apollo-server 包。
关注 v2 tutorial,安装 apollo-server-azure-functions@alpha
,graphql
,我们可能会继续使用 v2 代码。
const { gql, ApolloServer } = require("apollo-server-azure-functions");
// Construct a schema, using GraphQL schema language
const typeDefs = gql`
type Query {
hello: String
}
`;
// A map of functions which return data for the schema.
const resolvers = {
Query: {
hello: () => "world"
}
};
const server = new ApolloServer({ typeDefs, resolvers });
module.exports = server.createHandler();
请注意,在function.json
中,我们需要"name": "$return"
,而模板默认使用"name": "res"
。
{
"disabled": false,
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}