MyGit

machinebox/graphql

Fork: 220 Star: 939 (更新于 2024-11-19 06:59:09)

license: Apache-2.0

Language: Go .

Simple low-level GraphQL HTTP client for Go

最后发布版本: v0.2.2 ( 2018-05-31 22:28:32)

官方网址 GitHub网址

graphql GoDoc Build Status Go Report Card

Low-level GraphQL client for Go.

  • 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

Installation

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

$ go get github.com/machinebox/graphql

Usage

import "context"

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

// make a request
req := graphql.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. To enable the sending of files, you can opt to use multipart form data instead using the UseMultipartForm option when you create your Client:

client := graphql.NewClient("https://machinebox.io/graphql", graphql.UseMultipartForm())

For more information, read the godoc package documentation or the blog post.

Thanks

Thanks to Chris Broadfoot for design help.

最近版本更新:(数据更新于 2024-10-02 09:20:25)

2018-05-31 22:28:32 v0.2.2

2017-12-09 20:58:14 v0.2.1

2017-12-09 19:22:25 v0.2.0

2017-12-07 23:39:23 v0.1.0

主题(topics):

client, godoc, golang, graphql, machinebox, sdk

machinebox/graphql同语言 Go最近更新仓库

2024-11-22 20:14:47 daytonaio/daytona

2024-11-22 15:17:23 SagerNet/sing-box

2024-11-21 22:49:20 containerd/containerd

2024-11-21 13:50:50 XTLS/Xray-core

2024-11-21 07:36:18 kubernetes/kubernetes

2024-11-21 06:27:30 ollama/ollama