paljs / prisma-tools

Prisma tools to help you generate CRUD system for GraphQL servers
https://paljs.com
MIT License
683 stars 54 forks source link

Feature request: Generate single graphql schema file for prisma #156

Closed entrptaher closed 3 years ago

entrptaher commented 3 years ago

I want to generate a single graphql file from prisma instead of a lot of separate files/folders just like prisma 1. So there are two ways of doing this,

First way: import own types and use inside makeSchema.

import { makeSchema } from '@nexus/schema';
import * as types from './graphql';
import { paljs } from '@paljs/nexus';

export const schema = makeSchema({
  types,
  plugins: [paljs()],
  outputs: {
    schema: __dirname + '/generated/schema.graphql',
    typegen: __dirname + '/generated/nexus.ts',
  },
  typegenAutoConfig: {
    sources: [
      {
        source: '@prisma/client',
        alias: 'prisma',
      },
      {
        source: require.resolve('./context'),
        alias: 'Context',
      },
    ],
    contextType: 'Context.Context',
  },
});

Second way: generate the separate schema files and merge it back later.

import { Generator } from '@paljs/generator';
import rimraf from 'rimraf';

const { makeSchema } = require('@nexus/schema');
const { nexusSchemaPrisma } = require('nexus-plugin-prisma/schema');

async function main() {
  const tmpDir = './.temp';

  // generate all sdl
  await new Generator(
    { name: 'nexus-plugin-prisma', schemaPath: './prisma/schema.prisma' },
    { output: tmpDir, javaScript: true }
  ).run();

  // make schema from tmp dir
  await makeSchema({
    outputs: {
      schema: __dirname + '/test/output.graphql',
    },
    types: await import(tmpDir),
    plugins: [
      nexusSchemaPrisma({
        experimentalCRUD: true,
        shouldGenerateArtifacts: true,
      }),
    ],
  });

  await rimraf.sync(tmpDir);
}

main();

Would it be possible to generate the schema without directly without saving them to the disk and reading again?

For example, the Generator.run() could actually expose the string/code/object directly which we can use later.

AhmedElywa commented 3 years ago

Sorry but I do not understand what you want!

entrptaher commented 3 years ago

I got busy and forgot to reply on time. :D I'll ask you to reopen this with a reproducible code example.

entrptaher commented 3 years ago

Long story short, Paljs generator generates file in the disk, while I want to use them in stdin/tmp/stream file to add additional modification.

AhmedElywa commented 3 years ago

196 related to this issue