Where I am lost is, how do I reference this kind o...
# orm-help
c
Where I am lost is, how do I reference this kind of type:
LineItemCreateManyWithoutInvoiceInput
j
That looks, to me, to be a custom input-type that he created.
c
Na it’s a generated schema in Prsma
See the last answer in the forum
j
Aaah, yeah - I saw that after I sent 🙈 I've got no clue then. I've not gotten this far in my Prisma-journey yet.
c
😂 thanks man
j
Just tried to generate this and I found the
LineItemCreateManyWithoutInvoiceInput
.
Copy code
type Invoice @model {
  id: ID! @unique
  lineItems: [LineItem!]! @relation(name: "InvoiceItems")
}

type LineItem @model {
  id: ID! @unique
  invoice: Invoice! @relation(name: "InvoiceItems")
}
on line nr. 189 in the generated
schema.graphql
.
c
@Jenkins wow how did you generate that? My generated folder only has index.ts and prisma-schema.ts
j
I used the graphql-cli, but you can also use Prisma's generate. Under
generate:
in
prisma.yml
, add:
Copy code
- generator: graphql-schema
  output: ./path/to/generated
You saw the missing
.
? 😛
For shits-n-giggles, check your root directory and see if you have a /generated directory there...
c
hahah yeah. I am using:
Copy code
- generator: typescript-client
    output: ./generated/prisma-client/
typescript-client
not
graphql-schema
So it generates .ts files and no graphql file. But I need to import a graphql file where
LineItemCreateManyWithoutInvoiceInput
is generated in
When I did
Copy code
# import LineItemCreateManyWithoutInvoiceInput from "generated/prisma-client/prisma-schema.ts"
`
I got this error:
Syntax Error: Unexpected Name "generated"
cc @Jenkins
j
That's because you can't import that from a ts file. You need to generate the schema using what I wrote above and then you can import using the
# import x from "schema.graphql"
.
graphql-import requires a .graphql file.
I can throw together a quick example if you want?
c
thanks a lot. I got it now. Do you know the difference between the two — ts and graphql.
I chose the ts starter when setting up with prisma init but because the docs suggested that.
j
Yeah, the generator for typescript-client generates the client you use to interact with Prisma. Because TypeScript needs everything statically typed, the generated client holds all the type-information from your
datamodel.prisma
. Then, for either GraphQL-Yoga(which I'm guessing you're using) or ApolloServer, you need a
schema.graphql
. If you wanted to just directly expose your API to the world you could use said file in the
typeDefs
of the constructor. But most likely, especially with mutations, you want to hide certain parts. So that's when you create your own schema.graphql that you use with your server. To make it easy to reuse your models (Product, User, etc...) you can import them directly to your custom one from the generated. That way they're always in sync between your
datamodel.prisma
,
./generated/schema.graphql
and
./schema/my_custom_schema.graphql
. Makes sense? 🙂
c
Now you have made someone’s day — mine. Thank you so much for helping out.
❤️ 1
j
My pleasure 🦜