https://github.com/bbuck/graphql
An implementation of GraphQL for Go / Golang
https://github.com/bbuck/graphql
Last synced: 29 days ago
JSON representation
An implementation of GraphQL for Go / Golang
- Host: GitHub
- URL: https://github.com/bbuck/graphql
- Owner: bbuck
- License: mit
- Fork: true (graphql-go/graphql)
- Created: 2015-11-05T23:33:14.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-04-20T03:27:44.000Z (almost 8 years ago)
- Last Synced: 2024-06-20T16:50:04.114Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 2.54 MB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# graphql [](https://travis-ci.org/graphql-go/graphql) [](https://godoc.org/github.com/graphql-go/graphql) [](https://coveralls.io/github/graphql-go/graphql?branch=master) [](https://gitter.im/graphql-go/graphql?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
A *work-in-progress* implementation of GraphQL for Go.
### Getting Started
To install the library, run:
```bash
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.
```go
package main
import (
"encoding/json"
"fmt"
"log"
"github.com/graphql-go/graphql"
)
func main() {
// Schema
fields := graphql.FieldConfigMap{
"hello": &graphql.FieldConfig{
Type: graphql.String,
Resolve: func(p graphql.GQLFRParams) interface{} {
return "world"
},
},
}
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.Graphql(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/](https://github.com/graphql-go/graphql/tree/master/examples/) directory and [graphql_test.go](https://github.com/graphql-go/graphql/blob/master/graphql_test.go).
### Origin and Current Direction
This project was originally a port of [v0.4.3](https://github.com/graphql/graphql-js/releases/tag/v0.4.3) of [graphql-js](https://github.com/graphql/graphql-js) (excluding the Validator), which was based on the July 2015 GraphQL specification. `graphql` is currently several versions behind `graphql-js`, however future efforts will be guided directly by the [latest formal GraphQL specification](https://github.com/facebook/graphql/releases) (currently: [October 2015](https://github.com/facebook/graphql/releases/tag/October2015)).
### Third Party Libraries
| Name | Author | Description |
|:-------------:|:-------------:|:------------:|
| [graphql-go-handler](https://github.com/graphql-go/graphql-go-handler) | [Hafiz Ismail](https://github.com/sogko) | Middleware to handle GraphQL queries through HTTP requests. |
| [graphql-relay-go](https://github.com/graphql-go/graphql-relay-go) | [Hafiz Ismail](https://github.com/sogko) | Lib to construct a graphql-go server supporting react-relay. |
| [golang-relay-starter-kit](https://github.com/graphql-go/golang-relay-starter-kit) | [Hafiz Ismail](https://github.com/sogko) | Barebones starting point for a Relay application with Golang GraphQL server. |
### Blog Posts
- [Golang + GraphQL + Relay](http://wehavefaces.net/)
### Roadmap
- [x] Lexer
- [x] Parser
- [x] Schema Parser
- [x] Printer
- [x] Schema Printer
- [x] Visitor
- [x] Executor
- [ ] Validator
- [ ] Examples
- [ ] Basic Usage (see: [PR-#21](https://github.com/graphql-go/graphql/pull/21))
- [ ] React/Relay
- [ ] Alpha Release (v0.1)
The `Validator` is optional, per official GraphQL specification, but it would be a useful addition.