Skip to content

savaki/graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gographql

GoDoc Build Status

GraphQL implementation in go based on the working draft.

Status

The code works, but is far from production grade and does not implement the entire working draft. Exploring models for an executor, expect this to change

  • 2.1 Comments
  • 2.2 Names
  • 2.3 Document
  • 2.4 Operations
  • 2.5 Fields
  • 2.6 Field Selections
  • 2.7 Arguments
  • 2.8 Field Alias
  • 2.9 Input Values
  • 2.10 Variables
  • 2.11 Fragments
  • 2.12 Directives
  • 3. Type System
  • 4. Introspection
  • 5. Validation
  • 6. Execution
  • 7. Response
  • 8. Grammar

Overview

This is a Go implementation of GraphQL. The intent is to create a high quality library suitable for production deployments.

Hello World

The famous "hello world" in graphql:

package main

import (
	"os"

	"github.com/savaki/graphql"
	"github.com/savaki/graphql/provider/mapq"
)

func main() {
	model := map[string]interface{}{"hello": "world"}
	store := mapq.New(model)
	graphql.New(store).Handle(`{hello}`, os.Stdout)
	// prints {"hello":"world"}
}

Store

To implement a graphql service, one needs to implement the graphql.Store interface. For convenience and as examples, a number of default Store implementations are provided:

  • github.com/savaki/graphql/provider/mapq - access static map[string]interface{}
  • github.com/savaki/graphql/provider/jsonq - provides a rest gateway

Rest Call

Here's an example using the jsonq provider to access a generic rest service.

package main

import (
	"os"

	"github.com/savaki/graphql/provider/restq"
	"github.com/savaki/graphql"
)

func main() {
	query := `query city: GET("http://api.openweathermap.org/data/2.5/weather?q=London") {
		name
		weather: main {
			temperature: temp
		}
	}`

	store := restq.New()
	graphql.New(store).Handle(query, os.Stdout)
}

Refs

About

experimental implementation of graphql in go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages