go-graphql-server

module
v0.0.0-...-3f0a6de Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2021 License: MIT

README

go-graphql-server

GraphQL server sample using graphql-go/graphql

Requirements

  • Golang 1.16+
  • direnv for MacUser for environment variable. See .envrc
  • MySQL
    • Though MySQL is used in this sample, PostgreSQL must be better due to tool: PostGraphiles

Setup

cp example.envrc .envrc
direnv allow

Run server

make run

available query

#  curl [option] -g, --globoff: Disable URL sequences and ranges using {} and []
## Query
curl -g 'http://localhost:8080/graphql?query={user(id:"1"){id,name,age,country}}'
curl -g 'http://localhost:8080/graphql?query={userList{id,name}}'
## Mutation
curl -g 'http://localhost:8080/graphql?query=mutation+_{createUser(name:"Tom",age:15,country:"Japan"){id,name,age,country}}'
curl -g 'http://localhost:8080/graphql?query=mutation+_{updateUser(id:"1",name:"Dummy",age:99,country:"Japan"){id,name,age,country}}'
curl -g 'http://localhost:8080/graphql?query=mutation+_{deleteUser(id:"2"){id,name,age,country}}'
## Introspection
curl -g 'http://localhost:8080/graphql?query={__schema{types{name}}}'
curl -g 'http://localhost:8080/graphql?query={__schema{queryType{name}}}'
curl -g 'http://localhost:8080/graphql?query={__schema{types{name,kind,description}}}'
### All Available Queries
curl -g 'http://localhost:8080/graphql?query={__schema{queryType{fields{name,description}}}}'

TODO

  • add unittest
  • add integration test
  • how to sort response data??
  • use fragment
  • use onion type
  • use interface
  • use query variable
  • integrate graphiql into server
  • implement subscriptions
  • investigate about DataLoader
  • investigate about Apollo
  • integrate gRPC connection for micro services
  • return error filed in response when error occurred
  • investigate Introspection(https://graphql.org/learn/introspection/) pattern

References

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL