Cauen / prisma-generator-pothos-codegen

The fastest way to create a fully customizable CRUD Graphql API from Prisma Schema.
https://www.npmjs.com/package/prisma-generator-pothos-codegen
95 stars 16 forks source link

Nextjs examples? #60

Closed jimjamdev closed 5 months ago

jimjamdev commented 9 months ago

Is there any examples of getting this working in nextjs 14.

I'm looking at creating a gql server on app/api/graphql

import { ApolloServer } from '@apollo/server';
import { startServerAndCreateNextHandler } from '@as-integrations/next';
import { gql } from 'graphql-tag';
import { NextRequest } from 'next/server';

const resolvers = {
    Query: {
        hello: () => 'world',
    },
};

const typeDefs = gql`
    type Query {
        hello: String
    }
`;

const server = new ApolloServer({
    resolvers,
    typeDefs,
});

const handler = startServerAndCreateNextHandler<NextRequest>(server);

export async function GET(request: NextRequest) {
    return handler(request);
}

export async function POST(request: NextRequest) {
    return handler(request);
}

I'm currently generating everything, but not sure how to hook this up correctly.

Cauen commented 9 months ago

Hi @jimjamdev The Nextjs with Pothos is probably out of scope of this library

But i've already integrated in past and its how i've done.

  1. In /pages/api ive created a folder called /graphql
  2. In this /graphql folder i've setup Apollo Server at index.ts
  3. In index.ts i've imported and executed the autocrud functions

The server must works at http://localhost:3000/api/graphql

Let me know if this helped you