mirror of
https://github.com/lukaszraczylo/go-simple-graphql.git
synced 2026-10-17 01:17:43 +00:00
Add setting graphql server endpoint via environment variable.
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user