Categorygithub.com/leonardacademy/graphqlc
modulepackage
0.2.7
Repository: https://github.com/leonardacademy/graphqlc.git
Documentation: pkg.go.dev

# README

graphqlc GoDoc Build Status Go Report Card

Low-level GraphQL client for Go. This project was forked from machinebox's repo and includes some breaking changes, so some assembly is required if you are migrating from there.

  • Simple, familiar API
  • Respects context.Context timeouts and cancellation
  • Build and execute any kind of GraphQL request
  • Use strong Go types for response data
  • Use variables and upload files
  • Simple error handling
  • (Coming soon!) Subscriptions

Installation

Make sure you have a working Go environment. To install graphql, simply run:

$ go get github.com/leonardacademy/graphqlc

Usage

import "context"

// create a client (safe to share across requests)
client := graphqlc.NewClient("https://machinebox.io/graphql")

// make a request
req := graphqlc.NewRequest(`
        query ($key: String!) {
            items (id:$key) {
                field1
                field2
                field3
            }
        }
`)

// set any variables
req.Var("key", "value")

// set header fields
req.Header.Set("Cache-Control", "no-cache")

// define a Context for the request
ctx := context.Background()

// run it and capture the response
var respData ResponseStruct
if err := client.Run(ctx, req, &respData); err != nil {
    log.Fatal(err)
}

File support via multipart form data

By default, the package will send a JSON body. When files are included, the package transparently uses multipart form data instead.

For more information, read the godoc package documentation

Thanks

Thanks to Machinebox for creating the initial plugin.

# Packages

No description provided by the author

# Functions

NewClient makes a new Client capable of making GraphQL requests.
NewRequest makes a new Request with the specified string.

# Structs

Client is a client for interacting with a GraphQL API.
File represents a file to upload.
Request is a GraphQL request.
No description provided by the author

# Type aliases

ClientOption are functions that are passed into NewClient to modify the behaviour of the Client.