MCPcopy Index your code
hub / github.com/graphql-go/graphql

github.com/graphql-go/graphql @v0.8.1 sqlite

repository ↗ · DeepWiki ↗ · release v0.8.1 ↗
1,802 symbols 7,197 edges 120 files 306 documented · 17% 3 cross-repo links
README

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

Extension points exported contracts — how you extend this code

Input (Interface)
Input interface for types that may be used as input types for arguments and directives. [10 implementers]
definition.go
DescribableNode (Interface)
DescribableNode are nodes that have descriptions associated with them. [10 implementers]
language/ast/type_definitions.go
HasSelectionSet (Interface)
(no doc) [14 implementers]
validator.go
FieldResolver (Interface)
FieldResolver is used in DefaultResolveFn when the the source value implements this interface. [1 implementers]
executor.go
Extension (Interface)
Extension is an interface for extensions in graphql [1 implementers]
extensions.go
TypeInfoI (Interface)
TypeInfoI defines the interface for TypeInfo Implementation [1 implementers]
language/typeInfo/type_info.go
ExtendedError (Interface)
(no doc) [1 implementers]
gqlerrors/formatted.go
ValidationRuleFn (FuncType)
(no doc)
rules.go

Core symbols most depended-on inside this repo

NewObject
called by 249
definition.go
Diff
called by 237
testutil/testutil.go
RuleError
called by 224
testutil/rules_test_harness.go
ExpectPassesRule
called by 161
testutil/rules_test_harness.go
ExpectFailsRule
called by 153
testutil/rules_test_harness.go
NewNonNull
called by 136
definition.go
Error
called by 133
definition.go
NewList
called by 115
definition.go

Shape

Function 1,236
Method 346
Struct 158
FuncType 25
Interface 23
TypeAlias 14

Languages

Go100%
TypeScript1%

Modules by API surface

definition.go156 symbols
language/ast/type_definitions.go94 symbols
validation_test.go81 symbols
language/parser/parser.go65 symbols
rules_arguments_of_correct_type_test.go61 symbols
rules.go55 symbols
executor_test.go54 symbols
language/ast/values.go51 symbols
variables_test.go43 symbols
language/ast/definitions.go42 symbols
executor.go42 symbols
rules_overlapping_fields_can_be_merged_test.go39 symbols

Used by 3 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add graphql \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact