Giter Site home page Giter Site logo

graphql's Introduction

graphql Build Status GoDoc Coverage Status Join the chat at https://gitter.im/chris-ramon/graphql

A work-in-progress implementation of GraphQL for Go.

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.

Origin and Current Direction

This project was originally a port of v0.4.3 of 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 (currently: October 2015).

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.

Blog Posts

Roadmap

  • Lexer
  • Parser
  • Schema Parser
  • Printer
  • Schema Printer
  • Visitor
  • Executor
  • Validator
  • Examples
    • Basic Usage (see: PR-#21)
    • React/Relay
  • Alpha Release (v0.1)

graphql's People

Contributors

sogko avatar chris-ramon avatar fugitech avatar bbuck avatar lenaten avatar emergentbehavior avatar pavelnguyen avatar kr15h avatar slockij avatar deni64k avatar kazhuravlev avatar gitter-badger avatar alexstoick avatar samuel avatar switchtrue avatar kmulvey avatar jaredonline avatar augustoroman avatar

Watchers

 avatar Maksim Terekhin avatar James Cloos avatar Prakash Wadhwani avatar Lucas de Souza Santos avatar Simone Potenza avatar Felix Enescu avatar Yuri Buerov avatar Oxana avatar Anna Arteeva avatar Dmitrii Lobanov avatar Christian Gill avatar Djordy Seelmann avatar Vitaliy avatar Eldar avatar   avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.