Skip to content
This repository has been archived by the owner on Jan 8, 2023. It is now read-only.

Input Types generated incorrectly #53

Open
samrocksc opened this issue Jun 27, 2022 · 6 comments
Open

Input Types generated incorrectly #53

samrocksc opened this issue Jun 27, 2022 · 6 comments

Comments

@samrocksc
Copy link

samrocksc commented Jun 27, 2022

Given the following Schema:

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

generator graphql {
  provider   = "graphql-schema-generator"
  createCRUD = "true"
  output     = "../../resolvers/src/"

}

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

model Country {
  id          String      @id @unique @default(uuid())
  name        String      @db.VarChar(255)
  countryCode String      @unique @db.VarChar(255)
  createdAt   DateTime    @default(now())
  updatedAt   DateTime    @updatedAt
  Continent   Continent[]
}

model Continent {
  id        String  @id @unique @default(uuid())
  name      String  @db.VarChar(255)
  countryId String
  country   Country @relation(fields: [countryId], references: [id])
}

This generates the following schema:

"""
This file was generated by graphql-schema-generator which is
maintained by prisma-korea.

Do not make changes to this file directly.
Read more about in https://github.com/prisma-korea/graphql-schema-generator.
"""
type Query {
  country(id: ID!): Country
  countrys: [Country!]!
  continent(id: ID!): Continent
  continents: [Continent!]!
}

input CountryCreateInput {
  name: String!
  countryCode: String!
  createdAt: DateTime!
  updatedAt: DateTime!
  continent: Continent!
}

input CountryUpdateInput {
  name: String
  countryCode: String
  createdAt: DateTime
  updatedAt: DateTime
  continent: Continent
}

input ContinentCreateInput {
  name: String!
  Country: [Country!]!
}

input ContinentUpdateInput {
  name: String
  Country: [Country!]
}

type Mutation {
  createCountry(country: CountryCreateInput!): Country
  updateCountry(country: CountryUpdateInput!): Country
  deleteCountry(id: ID!): Country
  createContinent(continent: ContinentCreateInput!): Continent
  updateContinent(continent: ContinentUpdateInput!): Continent
  deleteContinent(id: ID!): Continent
}

scalar DateTime

type Country {
  id: ID!
  name: String!
  countryCode: String!
  createdAt: DateTime!
  updatedAt: DateTime!
  continent: Continent!
}

type Continent {
  id: ID!
  name: String!
  Country: [Country!]!
}

The issue


We should be making the relation here on the continentId instead of the Continent.

The error created

Error: The type of CountryCreateInput.continent must be Input Type but got: [Country!]!.

The type of CountryUpdateInput.continent must be Input Type but got: [Country!].

The type of ContinentCreateInput.country must be Input Type but got: Country!.
@yujonglee
Copy link
Member

yujonglee commented Jun 29, 2022

Yes. createCRUD is not feature-complete and has many broken cases. Currently, I don't have time to fix it. If you want to fix it, this can help you working with DMMF. If you have any question about contributing, feel free to ping me.

Also, If you are interested in developing graphQL API with Prisma, you might want to check out nounandverb.io(It is a project that I am working on). This will generate proper graphQL schema and more. See this for details.

Happy to help if you have any question about using nounandverb.io.

@irwinbraganza
Copy link

+1

@samrocksc
Copy link
Author

@yujong-lee thanks a lot for the info on DMMF, i'm looking into it right now.

Currently in the above example you can see that Continent is being left in the input, but it should be continentId: string!, if we want to effectively apply it back into the prisma client in the resolvers.

an example payload of a relation DMMF looks like:

{
      name: 'Continent',
      kind: 'object',
      isList: false,
      isRequired: false,
      isUnique: false,
      isId: false,
      isReadOnly: false,
      type: 'Continent',
      hasDefaultValue: false,
      relationName: 'ContinentToCountry',
      relationFromFields: ['continentId'],
      relationToFields: ['id'],
      isGenerated: false,
      isUpdatedAt: false,
    };

What are your thoughts on changing the DMMF's with an relationToFields.length of 1 to using the relationId only?

@yujonglee
Copy link
Member

yujonglee commented Jul 29, 2022

@samrocksc You mean using relationFromFields and relationToFields to fix it?

Yes. I think that is the right approach.

But one thing we should consider is that length of those fields can be greater than 1.

// Example

model User {
    id      String   @id @default(cuid())
    name    String
    profile Profile?

    @@unique([id, name])
}

model Profile {
    id        String @id @default(cuid())
    user      User   @relation(fields: [firstName, lastName], references: [id, name])
    firstName String
    lastName  String

    @@unique([firstName, lastName])
}

스크린샷 2022-07-29 오후 2 41 57

@eglove
Copy link

eglove commented Sep 11, 2022

Yes. createCRUD is not feature-complete and has many broken cases. Currently, I don't have time to fix it. If you want to fix it, this can help you working with DMMF. If you have any question about contributing, feel free to ping me.

Is this package abandoned? Should Prisma remove it from their generators page?

If this is depending on community support that it's not getting, it probably shouldn't be there.

@yujonglee
Copy link
Member

@eglove Yes. It is not being maintained right now. But I am not sure about whether it should be removed from the list or not.

Community projects are not maintained or officially supported by Prisma and some features may be out of sync. Use at your own discretion.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants