diff --git a/go.mod b/go.mod index 2c22791..621843f 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.16 require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/lukaszraczylo/zero v0.0.0-20160322155811-4a4535dd56e7 // indirect github.com/stretchr/testify v1.7.0 github.com/tidwall/gjson v1.7.3 github.com/valyala/fasthttp v1.22.0 diff --git a/go.sum b/go.sum index ce838de..a3a3137 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/klauspost/compress v1.11.8 h1:difgzQsp5mdAz9v8lm3P/I+EpDKMU/6uTMw1y1FObuo= github.com/klauspost/compress v1.11.8/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/lukaszraczylo/zero v0.0.0-20160322155811-4a4535dd56e7 h1:9l31ZdbJuSK5sQH4hldeHB/ulflee5srCFzT4Oxm65Q= +github.com/lukaszraczylo/zero v0.0.0-20160322155811-4a4535dd56e7/go.mod h1:UOwgylrs4V/Vzo1KfbjhzU+iB/5Pu4HnSpgE8WI14gs= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= diff --git a/gql.go b/gql.go index 6af1973..83401a7 100644 --- a/gql.go +++ b/gql.go @@ -9,12 +9,16 @@ import ( "encoding/json" "errors" "fmt" + "os" + "github.com/lukaszraczylo/zero" "github.com/tidwall/gjson" "github.com/valyala/fasthttp" ) // Endpoint of your GraphQL server to query +// this variable can be overwritten by setting env variable, for example: +// GRAPHQL_ENDPOINT=http://hasura.local/v1/graphql var GraphQLUrl = "http://127.0.0.1:9090/v1/graphql" type requestBase struct { @@ -22,6 +26,12 @@ type requestBase struct { Variables interface{} `json:"variables"` } +func init() { + if !zero.IsZero(os.Getenv("GRAPHQL_ENDPOINT")) { + GraphQLUrl = os.Getenv("GRAPHQL_ENDPOINT") + } +} + // queryBuilder takes query data (string) and variables (interface) as a parameter and assembles // graphQL query. It also compacts the JSON result. Function returns query as []byte and error if anything went wrong. func queryBuilder(data string, variables interface{}) ([]byte, error) {