gqlgen icon indicating copy to clipboard operation
gqlgen copied to clipboard

Automatically create resolvers for all fields

Open martinscholz83 opened this issue 2 years ago • 4 comments

What happened?

Currently to create a resolver for field you have to explicitly set this in the config file like this

Todo:
    fields:
      user:
        resolver: true

What did you expect?

Is there any way to by default create resolvers for all fields in the schema. Wether they are used or not.

Minimal graphql.schema and models to reproduce

versions

  • v0.17.34
  • 1.20

martinscholz83 avatar Jun 30 '23 07:06 martinscholz83

I'm also interested to see if this is possible.

tboley-vt avatar Aug 24 '23 07:08 tboley-vt

did you find any answer

subhroacharjee avatar Sep 01 '23 11:09 subhroacharjee

I remember that this was default earlier but seems like it is not anymore. Found an easier solution for that. Instead of adding each field to the gqlgen.yml you can declare the directive directive @goField(forceResolver: Boolean) on FIELD_DEFINITION in the schema and use it at each field you would like to have an explizit resolver.

directive @goField(forceResolver: Boolean) on FIELD_DEFINITION

type User {
  id: ID!
  mother: User! @goField(forceResolver: true)
}

micharaze avatar Jan 13 '24 18:01 micharaze

I've also been grasping for this feature

My first experience of a GraphQL server was one written in NodeJS (apollo-server and AWS AppSync), without configuration these frameworks allow you to define resolvers for fields of Types

I am finding it very difficult to develop using gqlgen. As I understand it I need to add config for every field on every type in all my schema files, in order to get a developer experience comparable to apollo server or similar NodeJS GQL framework.

SmileyJames avatar Jun 16 '24 10:06 SmileyJames