Struggling to navigate the graphql in apollo client/server for a Next.js project. The terminal is showing an error message
No HTTP methods exported in '..\app\api\graphql\route.ts'. Export a named export for each HTTP method.
. I'm still new to these technologies and unsure about the directory structure. All four files mentioned are located in the same folder app/api/graphql
.
Below are the code snippets:
ApolloClient.ts
import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client";
import { registerApolloClient } from "@apollo/experimental-nextjs-app-support/rsc";
export const { getClient } = registerApolloClient(() => {
return new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({
uri: "http://localhost:3000/api/graphql",
}),
});
});
typeDefs.ts
import { ApolloServer } from "@apollo/server";
import { gql } from "graphql-tag";
const typeDefs = gql`
type Query {
hello: String
}
`;
export default typeDefs;
resolver.ts
const resolvers = {
Query: {
hello: () => 'world',
},
};
export default resolvers;
graphql.ts
import { ApolloServer } from "@apollo/server";
import typeDefs from './typeDefs';
import resolvers from './resolvers';
import { startServerAndCreateNextHandler } from "@as-integrations/next";
const graphql = new ApolloServer({
resolvers,
typeDefs
});
export default startServerAndCreateNextHandler(graphql);
Error displayed on the browser:
Unhandled Runtime Error
Error: Response not successful: Received status code 405
Call Stack
- Traces of errors -