Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to actual versions #6

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
138 changes: 138 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

###########################################################
# common
# Unix-style newlines with a newline ending every file
###########################################################

[*]
charset = utf-8

end_of_line = LF
insert_final_newline = true
trim_trailing_whitespace = true

indent_style = space
indent_size = 4

###########################################################
; make
###########################################################

[Makefile]
indent_style = tab

[makefile]
indent_style = tab

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8
indent_size = 2
indent_style = space

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2

# JSON/YML
# 2 space indentation
[*.{json,yml}]
indent_style = space
indent_size = 2

# Bash
# https://google.github.io/styleguide/shell.xml#Indentation
# 2 space indentation
[*.sh]
indent_style = space
indent_size = 2

# C/C++/header files
# https://google.github.io/styleguide/cppguide.html#Spaces_vs._Tabs
# 2 space indentation
[*.{c,cpp,h,hpp}]
indent_style = space
indent_size = 2

# Java
# https://google.github.io/styleguide/javaguide.html#s4.2-block-indentation
# https://google.github.io/styleguide/javaguide.html#s4.5.2-line-wrapping-indent
[*.java]
indent_style = space
indent_size = 2
continuation_indent_size = 4

###########################################################
; markdown
###########################################################

[*.md]
trim_trailing_whitespace = false

# Golang
# https://golang.org/cmd/gofmt/
# Tab indentation (no size specified)
[*.go]
indent_style = tab
indent_size = 4

# HTML
# https://www.w3schools.com/html/html5_syntax.asp
[*.html]
# 2 space indentation
indent_style = space
indent_size = 2

# CSS/SASS/SCSS/LESS
# https://www.drupal.org/docs/develop/standards/css/css-formatting-guidelines#whitespace
[*.{css,sass,scss,less}]
# 2 space indentation
indent_style = space
indent_size = 2

# Vue
# https://github.com/vuejs/eslint-plugin-vue/blob/master/.editorconfig
# 2 space indentation
[*.vue]
indent_style = space
indent_size = 2

# Angular
# https://github.com/angular/angular/blob/master/.editorconfig
# 2 space indentation
[*.ts]
indent_style = space
indent_size = 2

# JSX
# https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent.md
# 4 space indentation
[*.jsx]
indent_style = space
indent_size = 4


# SQL (MySQL) - https://www.mysql.com/
[*.sql]
indent_style = space
indent_size = 2
112 changes: 94 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,24 +1,100 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
desktop.ini

# IDE files #
#############
nbproject
.~lock.*
.buildpath
.idea
.project
.settings
composer.lock

# Dotenv file
.env

# misc
.env.local
.env.development.local
.env.test.local
.env.production.local

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# generated files
generated.go
*.bak & *.swp

# csv files
*.csv

# Folders
_obj
_test
# node
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
# production
/build

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
# testing
/coverage

_testmain.go
# dependencies
/node_modules
/.pnp
.pnp.js


# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.test
*.prof
*.o
*.so

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip


# Video
*.wmv
*.mpg
*.mpeg
*.mp4
*.mov
*.flv
*.avi
*.ogv
*.ogg
*.webm

# Audio
*.wav
*.mp3
*.wma
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (e *GraphQLError) Error() string {
// Request ...
type Request struct {
Query string `json:"query"`
Variables map[string]interface{} `json:"variables"`
}

// Response ...
Expand Down
38 changes: 7 additions & 31 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package main

import (
"encoding/json"
"log"
"net/http"

"github.com/alexsuslov/go-graphiql"
"github.com/alexsuslov/go-graphiql/example/types"
"github.com/graphql-go/graphql"
"github.com/mnmtanish/go-graphiql"
"github.com/mnmtanish/go-graphiql/example/types"
)

func main() {
Expand All @@ -22,12 +21,12 @@ func main() {
go setMessage("Hello World")

http.HandleFunc("/", graphiql.ServeGraphiQL)
http.HandleFunc("/graphql", serveGraphQL(schema))
http.ListenAndServe(":9001", nil)
http.HandleFunc("/graphql", graphiql.ServeGraphQL(schema))
http.ListenAndServe(":9000", nil)
}

func setMessage(msg string) {
c, err := graphiql.NewClient("http://localhost:9001/graphql")
c, err := graphiql.NewClient("http://localhost:9000/graphql")
if err != nil {
panic(err)
}
Expand All @@ -38,33 +37,10 @@ func setMessage(msg string) {
panic(err)
}

if string(*res.Data) != `{"setMessage":"Hello World"}` {
if string(*res.Data) != `{"setMessage":"Hello Hubr"}` {
panic("bad response")
}

log.Println("listening on http://localhost:9001")
log.Println("listening on http://localhost:9000")
}

func serveGraphQL(s graphql.Schema) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
sendError := func(err error) {
w.WriteHeader(500)
w.Write([]byte(err.Error()))
}

req := &graphiql.Request{}
if err := json.NewDecoder(r.Body).Decode(req); err != nil {
sendError(err)
return
}

res := graphql.Do(graphql.Params{
Schema: s,
RequestString: req.Query,
})

if err := json.NewEncoder(w).Encode(res); err != nil {
sendError(err)
}
}
}
Loading