Some thoughts compared to graphqlgen
See original GitHub issueSo I just tried out https://github.com/prisma/graphqlgen and this library with the following template: graphql-codegen-typescript-template to create Typescript types for resolvers.
I wanted to give some feedback on some things I liked better about graphqlgen.
-
If a query/mutation doesn’t have any arguments, graphqlgen generates the args Typescript type as
{}
which I like better than the template which usesany
. -
graphqlgen let’s me set what the
Context
type is upfront, so I don’t have to doQueryResolvers.Resolvers<Context>
, I can just doQueryResolvers.Resolvers
. -
I’m not sure how to handle this case:
So my schema is this:
type Post {
id: ID!
title: String!
content: String!
published: Boolean!
author: User!
}
type User {
id: ID!
name: String
}
type Query {
post(id: ID!): Post
}
So in the post
resolver it expects me to return an author
, but I really want to return a authorId
and have the Post.author
resolver use the authorId
to fetch and return an author
. graphqlgen solves this by allowing you to create your own typescript types and it will use those.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
Hi @benawad
Each field has it’s own type that looks like this:
So you can:
@benawad If you are using dataloader to batch requests then it’s great 😃 Then your resolver should expect to get then full object and not just the id, but the linked resolvers should return
string
in order to fetch it from the dataloader.Then you should be able to use the generics to override the return value of each resolver, and set it to
string
. And with the latest version you can override theParent
value (using generics).Also, @kamilkisiela added a
mappers
features in this PR, so now you can also custom mapping between GraphQL types and TypeScript interfaces, and this way it will override it in the whole generated file (and then you don’t have to use generics each time).