gqlgenc icon indicating copy to clipboard operation
gqlgenc copied to clipboard

Create an interface with the client receiver functions

Open krissell opened this issue 3 years ago • 1 comments

The code generates the client receiver functions today. This request is to add those functions to an interface, so users can easily stub the interface out for unit testing.

Example: Today the client is generated for something like this, where th query geneated is 'AddNumbers':

type Client struct { Client *client.Client }

func NewClient(cli *http.Client, baseURL string, options ...client.HTTPRequestOption) *Client { return &Client{Client: client.NewClient(cli, baseURL, options...)} }

func (c *Client) AddNumbers( ... }


Ideally an interface would also be created with AddNumbers in it so client side code can create mock versions of the interface to test with. The NewClient would return the interface implemention. Something like:

type Client interface { AddNumbers(... }

type gqlClient struct { Client *client.Client }

func NewClient(cli *http.Client, baseURL string, options ...client.HTTPRequestOption) Client { return &gqlClient{Client: client.NewClient(cli, baseURL, options...)} }

func (c *gqlClient) AddNumbers( ... }

krissell avatar Oct 12 '21 13:10 krissell

https://github.com/Yamashou/gqlgenc/issues/81

Yamashou avatar Nov 04 '21 01:11 Yamashou