question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typegraphql-prisma doesn't create array field in output

See original GitHub issue

Hi,

I’m have created a tags array in the schema.prisma file, but when the output is generated, there isn’t a tags array that I created


datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

generator typegraphql {
  provider           = "typegraphql-prisma"
  output             = "../generated"
  emitTranspiledCode = true
}

model PostTags {
  id     String  @id @default(uuid())
  post   Post?   @relation(fields: [postId], references: [id])
  tag    Tag?    @relation(fields: [tagId], references: [id])
  postId String?
  tagId  String?
}

model Tag {
  id    String     @id @default(uuid())
  name  String     @unique
  posts PostTags[]
}

model Post {
  id        String     @id @default(uuid())
  title     String     @db.VarChar(255)
  tags      PostTags[] // THIS IS WHAT I'M TALKING ABOUT
  isVideo   Boolean?   @default(false)
  createdAt DateTime   @default(now())
  updatedAt DateTime   @updatedAt

  @@map("post")
}

model User {
  id       String @id @default(uuid())
  email    String @unique @db.VarChar(255)
  username String @unique @db.VarChar(50)
  /// @TypeGraphQL.omit(output: true)
  password String @db.Text
  // posts    Post[]
  role     Role   @default(USER)

  @@map("user")
}

enum Role {
  USER
  ADMIN
}

OUTPUT CODE.TS(tags array is generated here) :

import { PostTags } from "../models/PostTags";
import { User } from "../models/User";
export declare class Post {
  id: string;
  title: string;
  tags?: PostTags[];
  creator?: User;
  creatorId: string;
  url: string;
  isVideo?: boolean | null;
  createdAt: Date;
  updatedAt: Date;
}

OUTPUT CODE.JS(BUT NOTE HERE)

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Post = void 0;
const tslib_1 = require("tslib");
const TypeGraphQL = (0, tslib_1.__importStar)(require("type-graphql"));
const PostCount_1 = require("../resolvers/outputs/PostCount");
let Post = class Post {
};
(0, tslib_1.__decorate)([
    TypeGraphQL.Field(_type => String, {
        nullable: false
    }),
    (0, tslib_1.__metadata)("design:type", String)
], Post.prototype, "id", void 0);
(0, tslib_1.__decorate)([
    TypeGraphQL.Field(_type => String, {
        nullable: false
    }),
    (0, tslib_1.__metadata)("design:type", String)
], Post.prototype, "title", void 0);
(0, tslib_1.__decorate)([
    TypeGraphQL.Field(_type => String, {
        nullable: false
    }),
    (0, tslib_1.__metadata)("design:type", String)
], Post.prototype, "creatorId", void 0);
(0, tslib_1.__decorate)([
    TypeGraphQL.Field(_type => String, {
        nullable: false
    }),
    (0, tslib_1.__metadata)("design:type", String)
], Post.prototype, "url", void 0);
(0, tslib_1.__decorate)([
    TypeGraphQL.Field(_type => Boolean, {
        nullable: true
    }),
    (0, tslib_1.__metadata)("design:type", Boolean)
], Post.prototype, "isVideo", void 0);
(0, tslib_1.__decorate)([
    TypeGraphQL.Field(_type => Date, {
        nullable: false
    }),
    (0, tslib_1.__metadata)("design:type", Date)
], Post.prototype, "createdAt", void 0);
(0, tslib_1.__decorate)([
    TypeGraphQL.Field(_type => Date, {
        nullable: false
    }),
    (0, tslib_1.__metadata)("design:type", Date)
], Post.prototype, "updatedAt", void 0);
(0, tslib_1.__decorate)([
    TypeGraphQL.Field(_type => PostCount_1.PostCount, {
        nullable: true
    }),
    (0, tslib_1.__metadata)("design:type", PostCount_1.PostCount)
], Post.prototype, "_count", void 0);
Post = (0, tslib_1.__decorate)([
    TypeGraphQL.ObjectType("Post", {
        isAbstract: true
    })
], Post);
exports.Post = Post;

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MichalLytekcommented, Mar 23, 2022

You haven’t understood my previous post, but I think your approach would also work, so if you prefer that, you can do it that way 😉

0reactions
alisalim17commented, Mar 24, 2022

Oh, I can understand now what you said yesterday, to be honest, I hadn’t read that part of the docs. Thanks for your great explanation!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · MichalLytek/typegraphql-prisma - GitHub
Prisma generator to emit TypeGraphQL types and CRUD resolvers from your Prisma ... Allow connect but not create/connectOrCreate in generated input type ...
Read more >
Hiding Prisma model field in GraphQL schema
Sometimes you may want to not expose some fields in GraphQL schema. To achieve this, just put the @TypeGraphQL.omit doc line above the...
Read more >
Working with scalar lists/arrays (Concepts) - Prisma
When using scalar list filters with a relational database connector, array fields with a NULL value are not considered by the following conditions:...
Read more >
Do I have to create a new type to define array of objects in ...
In Prisma, you can use embedded types. You would drop the @relation directive and add @embedded directives to the types you're embedding:
Read more >
typegraphql-prisma - npm
Hiding Prisma model field in GraphQL schema. Sometimes you may want to not expose some fields in GraphQL schema. To achieve this, just...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found