question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Some thoughts compared to graphqlgen

See original GitHub issue

So 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.

  1. If a query/mutation doesn’t have any arguments, graphqlgen generates the args Typescript type as {} which I like better than the template which uses any.

  2. graphqlgen let’s me set what the Context type is upfront, so I don’t have to do QueryResolvers.Resolvers<Context>, I can just do QueryResolvers.Resolvers.

  3. 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:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
kamilkisielacommented, Oct 25, 2018

Hi @benawad

  1. it’s something we can fix asap.
  2. It’s is not implemented but we can do it 😃
  3. it’s possible, you can overwrite all: parent, context, returned value.

Each field has it’s own type that looks like this:

export type PostResolver<R = Post | null, Parent = any, Context = any> = Resolver<R, Parent, Context>;

So you can:

const postResolver: PostResolver<string>;
1reaction
dotansimhacommented, Nov 10, 2018

@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 the Parent 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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing gqlgen: a GraphQL Server Generator for Go
gqlgen is the best way to build a GraphQL server in Go and possibly even any language. This article looks at why and...
Read more >
Some thoughts on GraphQL vs. BFF - Phil Calçado
It follows then that it does not make much sense to compare BFFs and GraphQL. You can build your GraphQL APIs as many...
Read more >
Building a GraphQL API in Go using gqlgen | by Jigar - Servian
This article demonstrates how one can leverage existing open source tools in order to rapidly develop a GraphQL API in the Go programming...
Read more >
GraphQL with Golang: A Deep Dive From Basics To Advanced
GraphQL is a query language for APIs and runtime for fulfilling those queries with your existing data. GraphQL provides a complete and ...
Read more >
Type-Safe GraphQL Servers . This post exhibits the motivations
For some languages this means that you as programmer must specify what type each variable is (e.g.: Java, C, C++). ... GraphQL Code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found