英文:
How to start the graphql server in new version of next js 13.2 api route?
问题
无法启动 Next.js 13.2 中的服务器。
import { ApolloServer } from '@apollo/server';
import { startServerAndCreateNextHandler } from '@as-integrations/next';
const resolvers = {
Query: {
hello: () => 'world',
},
};
const typeDefs = `#graphql
type Query {
hello: String
}
`;
const server = new ApolloServer({
resolvers,
typeDefs,
});
export async function GET(request: Request) {
return startServerAndCreateNextHandler(server);
}
我尝试将 GraphQL 服务器集成到 Next.js 13.2 中的应用程序目录 API 路由,但对我来说无法正常工作。
英文:
Unable to start the server in next js 13.2.
import { ApolloServer } from '@apollo/server';
import { startServerAndCreateNextHandler } from '@as-integrations/next';
const resolvers = {
Query: {
hello: () => 'world',
},
};
const typeDefs = `#graphql
type Query {
hello: String
}
`;
const server = new ApolloServer({
resolvers,
typeDefs,
});
export async function GET(request: Request) {
return startServerAndCreateNextHandler(server);
}
I tried to integrate the graphql server in next js 13.2 app directory api route but it's not working for me.
答案1
得分: 1
除非您有不同的工作流程要求,否则您似乎缺少默认设置。
将 export async function ...
替换为
export default startServerAndCreateNextHandler(server);
这是关于在 NextJS 上进行示例集成的参考链接:
https://github.com/apollo-server-integrations/apollo-server-integration-next
英文:
Unless you have a different workflow requirement, you seem to be missing the default?
Replace export async function ...
to
export default startServerAndCreateNextHandler(server);
Here's the reference for sample integration on NextJS
https://github.com/apollo-server-integrations/apollo-server-integration-next
答案2
得分: 0
The @as-integrations/next
package hasn't been updated to work with this feature yet, but in the issues someone has modified the code to work.
英文:
The @as-integrations/next
package hasn't been updated to work with this feature yet, but in the issues someone has modified the code to work.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论