Pieter
08/05/2020, 6:54 PMcompanies
or userProfiles
table. When I run prisma introspect
it generates models that matches the table names, which results in nexus
generating "singular" and plural typings for the models, both being the actual table and model names (plural) so it results in duplicates in the typescript typings which means code doesn't compile.
I got over 3000 lines generated by prisma introspect and there's no proper intellisense to rename a model and all fields related to itjanpio
Pieter
08/05/2020, 7:35 PMjanpio
Pieter
08/05/2020, 7:40 PMPieter
08/05/2020, 7:40 PMPieter
08/05/2020, 7:41 PMjanpio
Pieter
08/05/2020, 7:43 PMjanpio
users
to User
- especially not in other languages. Hence we decided to not even try do to that.Pieter
08/05/2020, 7:43 PMjanpio
Pieter
08/05/2020, 7:44 PMjanpio
Pieter
08/05/2020, 7:44 PMjanpio
F2
that at least updates the references and relations as well at the same time.Pieter
08/05/2020, 7:44 PMPieter
08/05/2020, 7:44 PMjanpio
Pieter
08/05/2020, 7:45 PMPieter
08/05/2020, 7:45 PMjanpio
Pieter
08/05/2020, 7:46 PMjanpio
Pieter
08/05/2020, 7:47 PMPieter
08/05/2020, 7:48 PMjanpio
janpio
janpio
Pieter
08/05/2020, 7:50 PMPieter
08/05/2020, 7:50 PMjanpio
janpio
Pieter
08/05/2020, 7:51 PMjanpio
Pieter
08/05/2020, 7:51 PMjanpio
Pieter
08/05/2020, 7:52 PMprisma introspect
should be able to either guess whether all table names are plural/singular or if it cant guess it should ask in the cli before generating the schema. Most of the time teams will have a convention and use either singular or plural and not bothPieter
08/05/2020, 7:53 PMThe model naming is a convention. If you are fine with the table names, you can keep those as well.You say that, but then when you put nexus into the mix, you end up with types duplicated and typescript doesnt like that.
janpio
janpio
janpio
Pieter
08/05/2020, 7:54 PMnexus-plugin-prisma/schema
will go and look at your prisma schema and create types. For some stupid reason it wants to compile a new name for when its a plural, despite prisma2 using .findOne and findMany convention as opposed to prisma1 using singular/pluralPieter
08/05/2020, 7:55 PMProblem is that going from plural to singular is not a solved problem for all languages. In English it also only works in most cases. And many databases are inconsistent in their usage, so it is really hard to generalize.I agree. But if its so hard, why try to go the other direction?
Pieter
08/05/2020, 7:56 PMNexus made that decision (and thus creates this problem) independent of Prisma and how Prisma handles model names.Yeah I guess it's a bit of a bigger issue now. From a user's perspective nexus=prisma but I know there's different maintainers
janpio
Pieter
08/05/2020, 7:57 PMjanpio
But if its so hard, why try to go the other direction?
Pieter
08/05/2020, 7:57 PMPieter
08/05/2020, 7:57 PMjanpio
janpio
janpio
Ahmed
08/05/2020, 7:58 PMnexus-plugin-prisma
Pieter
08/05/2020, 7:58 PMintrospect
again and then do it all over again.janpio
janpio
janpio
janpio
npx prisma introspect --experimental-reintrospection
Ahmed
08/05/2020, 8:00 PMjanpio
Ahmed
08/05/2020, 8:00 PMPieter
08/05/2020, 8:02 PMPieter
08/05/2020, 8:02 PMno result
notification from vscodejanpio
graphql-nexus
, that is what I refer to here. Or the Slack channel #graphql-nexus. Where the issue lives is rather unimportant - it is a Nexus problem.Pieter
08/05/2020, 8:03 PMThat seems usefulnpx prisma introspect --experimental-reintrospection
janpio
model
definition, not where it is used as a type. (Trying that now myself and creating an issue)Pieter
08/05/2020, 8:04 PMso you can use nexus without prisma plugin maybe my plugin not have issues with pluralWhat is the side effect? no generated types for prisma context but still typings for the gql schema?
Pieter
08/05/2020, 8:04 PM(If you go with SDL first, please make that heard in an Nexus issue that the plural thing made you do that.)Will do
Pieter
08/05/2020, 8:05 PMjanpio
janpio
janpio
model
it seems - https://github.com/prisma/language-tools/issues/395 - so we have some room to improve there. Pretty new everything 😄Ahmed
08/05/2020, 8:07 PMAhmed
08/05/2020, 8:08 PMPieter
08/05/2020, 8:27 PMPieter
08/05/2020, 8:28 PMPieter
08/05/2020, 8:29 PMjanpio
Pieter
08/05/2020, 8:31 PMAhmed
08/05/2020, 8:32 PMPieter
08/05/2020, 8:34 PMclients
table which has a 1:1 relationship with companies
table, which has a column of owner
which is a foreign key of the id
column on clients
prisma.schema would render
model companies {
id Int @default(autoincrement()) @id
ownerId Int
clients clients @relation(fields: [ownerId], references: [id])
}
Pieter
08/05/2020, 8:34 PM@Pieter you mean using paljs?nope was a reply to @janpio about how introspection works otherwise
Pieter
08/05/2020, 8:35 PMownerId
should probably have a directive making it a foreign key right?
clients
should be client
but due to the model name being clients
from the table name, the field is also clients
even though it is singular.Pieter
08/05/2020, 8:36 PM[]
array syntaxjanpio
janpio
clients
) in Prisma schema world.janpio
Ahmed
08/05/2020, 8:39 PMjanpio
Pieter
08/05/2020, 8:39 PM@@map
when I use rename, but it adds it in the wrong place (probably because the one field EK is plural) which breaks everything
https://cloud.invisible.email/5zuGD70Qjanpio
janpio
janpio
Pieter
08/05/2020, 8:42 PMWe have the concept of "Introspection Configuration" that we want to tackle after Re-Introspection that should allow users like you to set their own preferences.
But even then the signular/plural thing is hard to get rid and will probably be some kind of wizard.+1 for some config. I agree its tough to solve it universally. You need some user input to really know which problems there are to solve. Config will help. Plural issues in general are hard, even for eng only. A wizard will be nice. Guess the correct model and ask the user in the cli wizard to hit enter if its correct or to fill in the correct name
Pieter
08/05/2020, 8:43 PMjanpio
Pieter
08/05/2020, 8:44 PMjanpio
janpio
Pieter
08/05/2020, 9:07 PMPieter
08/05/2020, 9:11 PMyarn run v1.22.4
$ prisma generate && ts-node --transpile-only scripts/generateApolloSchemas.ts
Environment variables loaded from prisma/.env
Error:
Error: The schema at "/prisma/schema.prisma" contains reserved keywords.
Rename the following items:
- "model AggregateBalance"
To learn more about how to rename models, check out <https://pris.ly/d/naming-models>
error Command failed with exit code 1.
Pieter
08/05/2020, 9:11 PMjanpio
Aggregate
. Also worth an issue, to double check if that makes sense even as part of model names.janpio
Pieter
08/06/2020, 8:04 AMjanpio
Pieter
08/06/2020, 8:21 AMjanpio
Pieter
08/06/2020, 8:22 AM