MyGit

graphql-go/graphql

Fork: 840 Star: 9907 (更新于 2024-10-29 19:01:29)

license: MIT

Language: Go .

An implementation of GraphQL for Go / Golang

最后发布版本: v0.8.1 ( 2023-04-11 02:20:23)

GitHub网址

graphql CircleCI Go Reference Coverage Status Join the chat at https://gitter.im/graphql-go/graphql

An implementation of GraphQL in Go. Follows the official reference implementation graphql-js.

Supports: queries, mutations & subscriptions.

Documentation

godoc: https://pkg.go.dev/github.com/graphql-go/graphql

Getting Started

To install the library, run:

go get github.com/graphql-go/graphql

The following is a simple example which defines a schema with a single hello string-type field and a Resolve method which returns the string world. A GraphQL query is performed against this schema with the resulting output printed in JSON format.

package main

import (
	"encoding/json"
	"fmt"
	"log"

	"github.com/graphql-go/graphql"
)

func main() {
	// Schema
	fields := graphql.Fields{
		"hello": &graphql.Field{
			Type: graphql.String,
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				return "world", nil
			},
		},
	}
	rootQuery := graphql.ObjectConfig{Name: "RootQuery", Fields: fields}
	schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)}
	schema, err := graphql.NewSchema(schemaConfig)
	if err != nil {
		log.Fatalf("failed to create new schema, error: %v", err)
	}

	// Query
	query := `
		{
			hello
		}
	`
	params := graphql.Params{Schema: schema, RequestString: query}
	r := graphql.Do(params)
	if len(r.Errors) > 0 {
		log.Fatalf("failed to execute graphql operation, errors: %+v", r.Errors)
	}
	rJSON, _ := json.Marshal(r)
	fmt.Printf("%s \n", rJSON) // {"data":{"hello":"world"}}
}

For more complex examples, refer to the examples/ directory and graphql_test.go.

Third Party Libraries

Name Author Description
graphql-go-handler Hafiz Ismail Middleware to handle GraphQL queries through HTTP requests.
graphql-relay-go Hafiz Ismail Lib to construct a graphql-go server supporting react-relay.
golang-relay-starter-kit Hafiz Ismail Barebones starting point for a Relay application with Golang GraphQL server.
dataloader Nick Randall DataLoader implementation in Go.

Blog Posts

最近版本更新:(数据更新于 2024-10-02 19:31:18)

2023-04-11 02:20:23 v0.8.1

2021-08-29 08:10:34 v0.8.0

2020-02-09 04:52:07 v0.7.9

2019-03-28 18:12:24 v0.7.8

2018-12-03 09:27:27 v0.7.7

2018-08-19 10:36:22 v0.7.6

2018-03-09 07:27:48 v0.7.5

2018-01-08 05:00:31 v0.7.4

2017-09-29 04:45:29 v0.7.3

2017-08-06 08:34:15 v0.7.2

主题(topics):

graphql, graphql-go, subscriptions

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

2024-11-06 07:46:48 dolthub/dolt

2024-11-06 03:37:39 containerd/containerd

2024-11-05 20:42:00 aurora-develop/aurora

2024-11-05 08:55:31 XTLS/Xray-core

2024-11-05 00:03:47 SagerNet/sing-box

2024-11-04 20:34:19 Permify/permify