这是indexloc提供的服务,不要输入任何密码
Skip to content

v0.6.0

Compare
Choose a tag to compare
@hgiasac hgiasac released this 18 Dec 03:57
· 71 commits to master since this release
3578c9b

Highlights

Custom scalar tag

Because the generator reflects recursively struct objects, it can't know if the struct is a custom scalar such as JSON. To avoid expansion of the field during query generation, let's add the tag scalar:"true" to the custom scalar. If the scalar implements the JSON decoder interface, it will be automatically decoded.

struct {
	Viewer struct {
		ID         interface{}
		Login      string
		CreatedAt  time.Time
		DatabaseID int
	}
}
// Output:
// {
//   viewer {
//	   id
//		 login
//		 createdAt
//		 databaseId
//   }	
// }
struct {
	Viewer struct {
		ID         interface{}
		Login      string
		CreatedAt  time.Time
		DatabaseID int
	} `scalar:"true"`
}
// Output
// { viewer }

Add mechanism to modify outgoing HTTP request

This feature allows reusing the same client amongst slightly different "configurations". We are able to use one single HTTP client in multitenant applications with different authentication headers.

func setAuthHeader(secret string) func(req *http.Request) {
	return func(req *http.Request) {
		req.Header.Add("x-hasura-admin-secret", secret)
	}
}

client := graphql.NewClient("http://localhost:8080/v1/graphql", nil)

// return new client wrapper with different authentication header
client2 := client.WithRequestModifier(setAuthHeader("hasura"))

Changelog

  • feat: add mechanism to modify outgoing http request (#23) @dbarrosop
  • feat: allow tagging of the field as having a scalar GraphQL type (#24) @nizar-m