I think my Box type from TypeScript is mixing with...
# orm-help
a
I think my Box type from TypeScript is mixing with prisma Box type. How can I solve it?
s
Hi Artur! Can you share the definition of
Box
you’ve used in the return type?
a
Hi!
Copy code
import { ObjectType, Field, ID, Float } from 'type-graphql';
import { User } from '../User/type';

@ObjectType()
export class Box {
    @Field(type => ID)
    id: string

    @Field(type => User)
    owner: User
    
    @Field({ nullable: true })
    name?: string

    @Field(type => Float, { nullable: true })
    balance?: number
}
my datamodel
Copy code
type User {
    id: ID! @id
	email: String! @unique
	password: String!
    name: String
	roles: [Role!]!
	boxes: [Box!]! @relation(link: INLINE)
}

type Box {
	id: ID! @id
	owner: User!
	name: String @default(value: "")
	balance: Float @default(value: 0)
}

enum Role {
	USER,
	ADMIN
}
Copy code
# -----------------------------------------------
# !!! THIS FILE WAS GENERATED BY TYPE-GRAPHQL !!!
# !!!   DO NOT MODIFY THIS FILE BY YOURSELF   !!!
# -----------------------------------------------

type AuthPayload {
  user: User!
  token: String!
}

type Box {
  id: ID!
  owner: User!
  name: String
  balance: Float
}

type Mutation {
  createBox(name: String!, balance: Float): Box!
  deleteBox(id: ID!): Box!
  signup(email: String!, password: String!, name: String): AuthPayload!
  login(email: String!, password: String!): AuthPayload!
}

type Query {
  boxes(orderBy: String): [Box!]!
  user: User!
  allUsers(filter: String): [User!]!
}

# The user's possible roles.
enum Role {
  ADMIN
  USER
}

type User {
  id: ID!
  email: String!
  password: String!
  name: String
  roles: [Role!]!
  boxes: [Box!]!
}
I made some tries with defining Box as PrismaBox from Prisma and using it for output type instead but first it was a dirty way, 2nd I could not ge boxes when owner is X because of type errors
finally this is my Context type:
Copy code
import { AuthUser } from './AuthUser';
import { Prisma } from './prisma';

export interface Context {
	user?: AuthUser;
	prisma: Prisma | any; // :(
}
Please for help if its possible
s
Can you use the
Box
type from the prisma-client definitions in your resolver return type? this should work.
a
it works without prisma type in context
s
Can you share your code base in a codesandbox?
a
which other files would you like to see?
I can pass some more details if you want
s
I’d be happy to take a look when you can send over a minimal CSB repro.
a
what is " CSB repro"
😉