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
100 stars 19 forks source link

Nextjs examples? #60

Closed jimjamdev closed 7 months ago

jimjamdev commented 1 year 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 11 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