Skip to content

Is there a way to auto deside when to call a resolver with a @goField(forceResolver: true) #3446

@fearfate

Description

@fearfate

What happened?

If I set a @goField(forceResolver: true) directive, it will be called anyway

What did you expect?

We need a mechanism to automatically determine whether to invoke a resolver, instead of manually parsing fields to determine whether to execute.

like this:

type Product {
        productId: ID!
        
        name: String!

        extraFields: Any
}

type Project implements Node {
	id: ID!
        
        name: String!

	products: [Product!] @goField(forceResolver: true, forceResolverIgnoredKeys: ["productId", "name"])
}

type Query {
        project(id: ID!) Project!
}

the query will not call the products resolver in Project

query  {
        project(id: "xxxxx") {
                 id
                 name
                 products {
                         productId  # or name or both of them
                 }
        }
}

the query will call resolver

query  {
        project(id: "xxxxx") {
                 id
                 name
                 products {
                         productId
                         name
                         extraFields
                 }
        }
}

Minimal graphql.schema and models to reproduce

None

versions

  • go run github.com/99designs/gqlgen version? v0.17.61
  • go version? go version go1.23.4 linux/amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions