package module
Version: v1.6.2 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2021 License: Apache-2.0 Imports: 10 Imported by: 11



Simple GraphQL client for executing mutations and queries.


Copyright 2020, 2021, Ardan Labs


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.

About The Project

Package graphql provides support for executing mutations and queries against a database using GraphQL. It was designed specifically for working with Dgraph.

All of the documentation can be found on the website.



Package graphql provides client support for executing graphql requests against a host that supports the graphql protocol.



This section is empty.


This section is empty.


func WithClient added in v1.4.4

func WithClient(client *http.Client) func(gql *GraphQL)

WithClient adds a custom client for processing requests. It's recommend to not use the default client and provide your own.

func WithHeader added in v1.4.4

func WithHeader(key string, value string) func(gql *GraphQL)

WithHeader adds a key/value pair to the request header for all calls made to the host. This is for things like authentication or application specific needs. These headers are already included: "Cache-Control": "no-cache", "Content-Type": "application/json", "Accept": "application/json"

func WithLogging added in v1.6.0

func WithLogging(logFunc func(s string)) func(gql *GraphQL)

WithLogging acceps a function for capturing raw execution messages for the purpose of application logging.

func WithVariable added in v1.5.0

func WithVariable(key string, value interface{}) func(m map[string]interface{})

WithVariable allows for the submission of variables when executing graphql against the host for queries that supports variable substitution.


type GraphQL

type GraphQL struct {
	// contains filtered or unexported fields

GraphQL represents a client that can execute graphql and raw requests against a host.

func New

func New(url string, options ...func(gql *GraphQL)) *GraphQL

New constructs a GraphQL that can be used to execute graphql and raw requests against the specified url. The url represents a fully qualified URL without the `graphql` endpoint attached. If `/graphql` is provided, it's trimmed off.

func (*GraphQL) Execute added in v1.6.0

func (g *GraphQL) Execute(ctx context.Context, graphql string, response interface{}, variables ...func(m map[string]interface{})) error

Execute performs a graphql request against the configured host on the url/graphql endpoint.

func (*GraphQL) ExecuteOnEndpoint added in v1.6.0

func (g *GraphQL) ExecuteOnEndpoint(ctx context.Context, endpoint string, graphql string, response interface{}, variables ...func(m map[string]interface{})) error

ExecuteOnEndpoint performs a graphql request against the configured host on the specified url/endpoint

func (*GraphQL) RawRequest added in v1.6.0

func (g *GraphQL) RawRequest(ctx context.Context, endpoint string, r io.Reader, response interface{}) error

RawRequest performs the actual execution of a request against the specified url/endpoint. Use this function only when the request doesn't require a graphql document wrapper.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL