Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
entrptaher opened this issue Nov 16, 2020 · 4 comments
Closed

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

entrptaher opened this issue Nov 16, 2020 · 4 comments
Assignees
Labels
feature New feature or request question Further information is requested
Projects

Comments

@entrptaher
Copy link

entrptaher commented Nov 16, 2020

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
Copy link
Collaborator

Sorry but I do not understand what you want!

@AhmedElywa AhmedElywa self-assigned this Nov 16, 2020
@AhmedElywa AhmedElywa added feature New feature or request question Further information is requested labels Nov 16, 2020
@AhmedElywa AhmedElywa added this to To do in Dashboard via automation Nov 16, 2020
Dashboard automation moved this from To do to Done Jan 5, 2021
@entrptaher
Copy link
Author

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

@AhmedElywa AhmedElywa reopened this Jan 5, 2021
Dashboard automation moved this from Done to In progress Jan 5, 2021
@entrptaher
Copy link
Author

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 AhmedElywa moved this from In progress to To do in Dashboard Feb 17, 2021
@AhmedElywa
Copy link
Collaborator

#196 related to this issue

Dashboard automation moved this from To do to Done May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request question Further information is requested
Projects
Dashboard
  
Done
Development

No branches or pull requests

2 participants