Hi friends im fairly new to graphql and prisma and...
# orm-help
k
Hi friends im fairly new to graphql and prisma and working them together. Do people generally use code-first approach (TypeGraphQL) or sdl first? if you're using sdl-first is there a way to convert the models defined in schema.prisma to generate typedefs for gql?
r
Usually folks prefer the Code first approach, but you can use generators like this to generate CRUD operations if using SDL first as well.
k
hmm i'm not sure whta you mean by generate CRUD operations. Maybe i am having a disconnect. I'm assuming you need to define types for the tables you want to interface with. For example 1. i have a
PersonDB
type which is a type i have created that matches my person table. 2. I have a custom type called
Person
which is going to contain some aggregated data for a person which pulls in data from a number of tables. This is what i will generally be querying. 3. As you can see i need to now define the ContactDetailsDB type which matches the contactdetails table.
Copy code
const typeDefs = gql`
    type PersonDB {
        id: String!
        name: String!
        slug: String!
        synchronizationId: Int
        about: String
        profileImageId: String
        bannerId: String
        createdAt: String
        updatedAt: String
        deletedAt: String
    }

    type Person {
        base: PersonDB
        contactDetails: [ContactDetailDB]
    }
`;
Obviously this is going to be a long process because it means i need to create types for all of my database tables. Which makes the SDL first approach very time consuming and adds a lot to maintenance
r
Yes, so you need to create the typedefs and the resolvers in SDL first. Code first automatically generates typedefs based on your resolvers.