With grapqhlgen how do you get prompt the typescript types to create?


#1

Hi guys, silly question if someone could help please. With grapqhlgen how do you get prompt they typescript types to create?

I never been prompted with this config:


schema: ./src/schemas/schema.graphql
context: ./src/types:Context
models:
    files:
        - ./src/types.ts
        - ../prisma-service/src/generated/prisma-client/index.ts

output: ./src/generated/graphqlgen.ts

resolver-scaffolding:
    output: ./src/generated/tmp-resolvers/
    layout: file-per-type```

#2

You just run graphqlgen command to create the types. It will automatically read the config and generate the type

Let me know if your question is different.


#3

Hi @pantharshit00,

Thanks for your reply, I realised my question isn’t specific enough.

I had the impression that you can be suggested the models types in typescript in your terminal, based on your sdl.
But the model is a required configuration field.


#4

Models are the graphql to typescript mappings that graphqgen will use. This encourges further type safety.
Prisma generated this for you in the index.ts file so you don’t need to worry about it.

Here is the configuration that works well for me : https://github.com/javascript-af/javascript-af/blob/master/packages/backend/graphqlgen.yml

I think you can watch this video and look how model works: https://www.youtube.com/watch?v=6ZSF60zVFow

Basically we allow you to customise the interface that we will use.


#5

Hi!

Yes I know there are the prisma generated types, but my SDL differs from my prisma types.

But thanks for the video: https://youtu.be/6ZSF60zVFow?t=287 at this point is probably the solution I was looking for.
If I don’t have the types they will be prompted! And the types prompted I assume must matching my SDL!

I will try now!


#6

I just tried, but the types don’t really match my SDL.

It only includes the scalar types, not custom types.

For example:

export interface Post {
    id: string;
    title: string;
    content: string;
    isAvailable: boolean;
}

Where my SDL is:

type Post {
    id: ID!
    title: String!
    content: String!
    comments: [Comment!]
    user: User!
}

#7

If you feel like this is a bug you can open an issue in the graphqlgen repo


#8

It is a good idea! Thanks


#9

#10

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.