paljs / prisma-tools

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

[nexus] Input types generation as a file #196

Closed durdenx closed 3 years ago

durdenx commented 3 years ago

Hi, Thanks for the lib!

Is it possible to generate nexus input types as a file instead of runtime generation? We want to customize the default input types. It would be great if the generator generated input types alongside other files (types, query and mutations).

AhmedElywa commented 3 years ago

Hi by version 3.3.1 you can customize your inputs by adding new options to the paljs plugin

import { makeSchema } from 'nexus'
import * as types from './types'
import { paljs } from '@paljs/nexus'
import { join } from 'path'

export const schema = makeSchema({
  types,
  nonNullDefaults: {
    output: true,
  },
  plugins: [
    paljs({
// exclude all fields with this names from any input
      excludeFields: [
        'password',
        'passwordResetToken',
        'tokenValidDate',
        'passResetExpires',
      ],
// take the input and make your filters then return the fields you want to add 
filterInputs: (input: DMMF.InputType) => input.fields.filter(field => filed.name !== 'password');
    }),
  ],
  outputs: {
    schema: join(__dirname, '../src/generated/schema.graphql'),
    typegen: join(__dirname, '../src/generated/nexus.ts'),
  },
  contextType: {
    module: join(__dirname, 'context.ts'),
    export: 'Context',
  },
})