goQL

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: MIT Imports: 11 Imported by: 0

README

goQL

goQL is a graphql HTTP client,with 🔋 included

goql-logo

⚡️ Quickstart

package main

import "github.com/kushalshit27/goQL"

func main() {
   	const GRAPHQL_URL = "{{ graphql URL }}"
	
	c := goQL.New().
            SetURL(GRAPHQL_URL).
            SetMethod("POST").
            Build()
	
	q:= `query {
		post {
		  id
		  title
		  body
		}
            }`

	query := goQL.Query{
		Query: q,
	}

	response := c.Query(query).Run(context.TODO())

	log.Println(response)
}
✨ Features:

goQL.Query and goQL.Mutation supports more features like:

  • Debug(): Enables debug logging for the query execution, providing additional information about the request and response.(example)
  • RetryAttempts(..): Configures the client to retry the query in case of errors.(example)
  • RetryBackoff(...): Defines a linear backoff strategy for retries. This means the waiting time between retries increases linearly with each attempt.(example)
  • RetryOn(func(err error) bool { ... }): Defines a custom retry logic based on the encountered error. For example, The provided function checks if the error message contains the word "timeout", indicating a connection timeout scenario. In such cases, the query will be retried.(example)
  • RetryAllowStatus(func(status int) bool { ... }): Sets conditions for retrying on specific HTTP status codes returned by the database. The provided function allows retries for status.(example)

⚙️ Installation

go get -u github.com/kushalshit27/goQL

Usage

For more examples, please refer to the example

Roadmap

See the open issues for a list of proposed features (and known issues).

License

Distributed under the MIT License. See LICENSE for more information.

Documentation

Index

Constants

View Source
const Version = "1.0.0"

Version of current goql package

Variables

Functions

func DefaultAllowRetryStatus added in v1.2.0

func DefaultAllowRetryStatus() func(int) bool

func DefaultTransientError added in v1.2.0

func DefaultTransientError(err error) bool

DefaultTransientError checks if the error is transient

func ExponentialBackoff added in v1.2.0

func ExponentialBackoff(base time.Duration) backoffFunc

func LinearBackoff added in v1.2.0

func LinearBackoff(duration time.Duration) backoffFunc

Types

type GoQL

type GoQL struct {
	// contains filtered or unexported fields
}

func (*GoQL) Mutation

func (g *GoQL) Mutation(query Query) GoQLClientRunner

func (*GoQL) Query

func (g *GoQL) Query(query Query) GoQLClientRunner

type GoQLBuilder

type GoQLBuilder interface {
	SetURL(url string) GoQLBuilder
	SetHeader(name, value string) GoQLBuilder
	SetPayload(r io.Reader) GoQLBuilder
	SetMethod(method string) GoQLBuilder
	SetTimeout(seconds int) GoQLBuilder
	SetRetry(retryCount int) GoQLBuilder
	Build() GoQLClient
}

func New

func New() GoQLBuilder

type GoQLClient

type GoQLClient interface {
	Query(q Query) GoQLClientRunner
	Mutation(m Query) GoQLClientRunner
}

GoQLClient is an interface for a GraphQL HTTP client.

It provides two methods, `Query()` and `Mutation()`, for making GraphQL queries and mutations, respectively.

type GoQLClientError added in v1.2.0

type GoQLClientError struct {
	Description string
	// contains filtered or unexported fields
}

type GoQLClientResponse added in v1.2.0

type GoQLClientResponse map[string]interface{}

type GoQLClientRunner

type GoQLClientRunner interface {
	Run(ctx context.Context) (GoQLClientResponse, *GoQLClientError)
	Debug() GoQLClientRunner
	RawReq() GoQLClientRunner
	RawRes() GoQLClientRunner
	RetryAttempts(count int) GoQLClientRunner
	RetryBackoff(backoff backoffFunc) GoQLClientRunner
	RetryOn(fn func(err error) bool) GoQLClientRunner
	RetryAllowStatus(fn func(int) bool) GoQLClientRunner
}

type Query

type Query struct {
	Query     string `json:"query"`
	Variables `json:"variables,omitempty"`
}

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

func (*Runner) Debug added in v1.2.0

func (r *Runner) Debug() GoQLClientRunner

func (*Runner) RawReq

func (r *Runner) RawReq() GoQLClientRunner

func (*Runner) RawRes

func (r *Runner) RawRes() GoQLClientRunner

func (*Runner) RetryAllowStatus added in v1.2.0

func (r *Runner) RetryAllowStatus(fn func(int) bool) GoQLClientRunner

func (*Runner) RetryAttempts added in v1.2.0

func (r *Runner) RetryAttempts(count int) GoQLClientRunner

func (*Runner) RetryBackoff added in v1.2.0

func (r *Runner) RetryBackoff(backoff backoffFunc) GoQLClientRunner

func (*Runner) RetryOn added in v1.2.0

func (r *Runner) RetryOn(fn func(err error) bool) GoQLClientRunner

func (*Runner) Run

type Variables

type Variables struct {
	Filter interface{} `json:"filter,omitempty"`
	Input  interface{} `json:"input,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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