Skip to content

Can't make interface general resolvers #1896

Answered by duckbrain
chav-aniket asked this question in Q&A
Discussion options

You must be logged in to vote

The Go interfaces generated by gqlgen will only contain the one method to identify them. You basically have two options.

  1. Type assert to a concrete type. The Stocklist passed to your resolver is either a Watchlist or Portfolio. You can do something like the following to get the concrete value to work with.
swtich v := obj.(type) {
case WatchList:
	// v is a WatchList here
case Portfolio:
	// v is a Portfolio here
}
  1. Define the Stocklist interface yourself. gqlgen can pick up existing model types. You can define a different set of methods and the resolver will be able to access them. You'll just need to make sure you satisfy that interface for Watchlist and Portfolio. (Don't define things…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@chav-aniket
Comment options

Answer selected by chav-aniket
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1705 on February 04, 2022 00:41.