Yamashou / gqlgenc

This is Go library for building GraphQL client with gqlgen
MIT License
370 stars 66 forks source link

Create an interface with the client receiver functions #87

Open krissell opened 3 years ago

krissell commented 3 years ago

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( ... }

Yamashou commented 3 years ago

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