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

Empty codegen #48

Closed drfarr closed 1 year ago

drfarr commented 1 year ago

I'm under the impression that the result of builder.toSchema() used in conjunction with generateAllCrud(); should allow me to generate the relevant graphql-codegen files in my repo.

However when I run the codegen the contents of the generated schema.graphql is:

type Mutation

type Query

I assume I am missing something, it doesn't seem like the builder in the generateAllCrud function seem to contain the correct references to queryFields etc. Although the files and folders for them have been generated and are accessible ans present in the generateAllCrud file. If you could point me in the right direction would be much appreciated!

codegen.ts

import { printSchema } from "graphql";
import { schema } from "./src/schema";

module.exports = {
  overwrite: true,
  schema: printSchema(schema),
  generates: {
    "src/generated/index.ts": {
      plugins: [
        "typescript",
        "typescript-operations",
        "typescript-react-apollo",
      ],
      config: {
        withHooks: true,
      },
    },
    "src/generated/schema.graphql": { plugins: ["schema-ast"] },
  },
};

schema.ts

import { generateAllCrud } from "@clippy/schema/dist/autocrud";
import { builder } from "../";
generateAllCrud();

builder.queryType({});
builder.mutationType({});

export const schema = builder.toSchema();

builder.ts

import SchemaBuilder from "@pothos/core";
import PrismaPlugin from "@pothos/plugin-prisma";
import type { PrismaTypes } from "@clippy/db";
import { db, PrismaClient, Prisma } from "@clippy/db";
import { Scalars } from "prisma-generator-pothos-codegen";

export const builder = new SchemaBuilder<{
  Scalars: Scalars<
    Prisma.Decimal,
    Prisma.InputJsonValue | null,
    Prisma.InputJsonValue
  >;
  PrismaTypes: PrismaTypes;
  Context: {
    prisma: PrismaClient;
  };
}>({
  plugins: [PrismaPlugin],
  prisma: {
    client: db,
  },
});

pothos.config.js

/** @type {import('prisma-generator-pothos-codegen').Config} */
module.exports = {
  inputs: {
    outputFilePath: "../../packages/schema/src/index.ts",
  },
  crud: {
    generateAutocrud: true,
    outputDir: "../../packages/schema/src",
    inputsImporter: `import * as Inputs from '@clippy/schema';`,
    deleteOutputDirBeforeGenerate: true,
  },
  global: {
    builderImporter: `import { builder } from '@clippy/graphql';`,
  },
};
Cauen commented 1 year ago

Hello @drfarr , I don't know if I understood the problem right here Does it mean that if generateAllCrud is called, the graphql-codegen doesn't work correctly? And does it work again if you comment generateAllCrud?