go-graphql-server
GraphQL server sample using graphql-go/graphql
Requirements
- Golang 1.16+
- direnv for MacUser for environment variable. See
.envrc
- MySQL
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