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

Introduce `@Pal.omit` attribute #235

Closed dimaip closed 3 years ago

dimaip commented 3 years ago

Resolves: https://github.com/paljs/prisma-tools/issues/234

Put this kind of comment to hide a field from the generated types:

model User {
  /// @Pal.omit([input,output])
  password      String?
  /// @Pal.omit
  email             String?
}

Documentation: https://github.com/paljs/docs/pull/8

AhmedElywa commented 3 years ago
private static checkOmit(docs?: string, name?: 'input' | 'output') {
    const value = docs?.match(/@Pal.omit\(\[(.*?)\]\)/);
    if (value && name) {
      const asArray = value[1]
        .replace(/ /g, '')
        .split(',')
        .filter((v) => v);
      return asArray.includes(name);
    }
    return false;
  }