-
I would like to know what should be the proper way to set typegraphql with Nextjs13 with the experimental app directory. import { TypeGraphQLServer } from "next-type-graphql";
import { NextRequest } from "next/server";
import { resolvers } from "../../../../prisma/generated/type-graphql";
export const apolloServer = new TypeGraphQLServer({
path: "/api/graphql",
context: (ctx) => ctx,
schema: {
resolvers,
},
});
export async function GET(request: NextRequest) {
return apolloServer.createHandler();
}
export async function POST(request: NextRequest) {
return apolloServer.createHandler();
} And I'm getting this log:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I managed to set up the server and start it like this: import "reflect-metadata";
import { ApolloServer } from "@apollo/server";
import { startServerAndCreateNextHandler } from "@as-integrations/next";
import { buildSchema } from "type-graphql";
import { NextRequest } from "next/server";
import { resolvers } from "../../../../prisma/generated/type-graphql";
export async function GET(request: NextRequest) {
const schema = await buildSchema({
resolvers,
validate: false,
});
const server = new ApolloServer({
schema,
formatError: (error) => error,
});
const handler = startServerAndCreateNextHandler<NextRequest>(server, {
context: async (req) => ({ req }),
});
return handler(request);
}
export async function POST(request: NextRequest) {
const schema = await buildSchema({
resolvers,
});
const server = new ApolloServer({
schema,
});
const handler = startServerAndCreateNextHandler<NextRequest>(server, {
context: async (req) => ({ req }),
});
return handler(request);
} But now when I try to do a query or a mutation I get this response; {
"data": {},
"errors": [
{
"message": "Argument Validation Error",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": ["findManyPais"],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"stacktrace": [
"Error: Argument Validation Error",
" at validateArg (webpack-internal:///(sc_server)/./node_modules/type-graphql/dist/resolvers/validate-arg.js:63:15)",
" at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
" at async Promise.all (index 2)"
]
}
}
]
} |
Beta Was this translation helpful? Give feedback.
-
I solved it like this and it's working: export async function GET(request: NextRequest) { const server = new ApolloServer({
}); const handler = startServerAndCreateNextHandler(server, { export async function POST(request: NextRequest) { const schema = await buildSchema({ const server = new ApolloServer({ const handler = startServerAndCreateNextHandler(server, { |
Beta Was this translation helpful? Give feedback.
I solved it like this and it's working:
import "reflect-metadata";
import { ApolloServer } from "@apollo/server";
import { startServerAndCreateNextHandler } from "@as-integrations/next";
import { buildSchema } from "type-graphql";
import { NextRequest } from "next/server";
import { resolvers } from "../../../../prisma/generated/type-graphql";
import { PrismaClient } from "@prisma/client";
export async function GET(request: NextRequest) {
const schema = await buildSchema({
resolvers,
validate: false,
});
const server = new ApolloServer({
schema,
});
const handler = startServerAndCreateNextHandler(server, {
context: async (req) => ({ req }),
});
return handle…