graphql/yoga-server/v2 #813
Replies: 4 comments 16 replies
-
Awesome! |
Beta Was this translation helpful? Give feedback.
-
Hello, I use graphql-yoga version "1.18.3". Do you have a tuto to migrate in version 2.
|
Beta Was this translation helpful? Give feedback.
-
Hello, I use graphql-yoga version "1.18.3". Do you have a tuto to migrate in version 2. GraphQLServer, GraphQLServerLambda |
Beta Was this translation helpful? Give feedback.
-
I tried this method to use Graphql-Yoga with Prisma, type-graphql, and nuxtjs inside of a index.ts file: import "reflect-metadata";
import { buildSchema } from "type-graphql";
import { createServer } from '@graphql-yoga/node'
import * as path from "path";
import { PrismaClient } from "@prisma/client";
import { resolvers } from "../prisma/generated/type-graphql";
interface Context {
prisma: PrismaClient;
}
async function main() {
const schema = await buildSchema({
resolvers,
emitSchemaFile: path.resolve(__dirname, "./generated-schema.graphql"),
validate: false,
});
const prisma = new PrismaClient();
await prisma.$connect();
const server = createServer({
schema,
cors: {
origin: 'http://localhost:4000',
credentials: true,
allowedHeaders: ['X-Custom-Header'],
methods: ['POST'],
},
context: (): Context => ({ prisma }),
});
// Start the server and explore http://localhost:4000/graphql
server.start();
console.log(`GraphQL is listening on ${origin}!`);
}
main().catch(console.error); to run the file Install ts-node with npm i ts-node Yoga is now at http://127.0.0.1:4000/graphql I had such a hard time figuring this out, thanks to numerous articles this setup worked. |
Beta Was this translation helpful? Give feedback.
-
graphql/yoga-server/v2
Guild Docs Example
https://www.the-guild.dev/graphql/yoga-server/v2
Beta Was this translation helpful? Give feedback.
All reactions