Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TECHPULSE 2019 - Go-ing GraphQL in LINE SPOT API Gateway for Microservices

TECHPULSE 2019 - Go-ing GraphQL in LINE SPOT API Gateway for Microservices

BY Denny Tsai@LINE TECHPULSE 2019 https://techpulse.line.me/

LINE Developers Taiwan

December 04, 2019
Tweet

More Decks by LINE Developers Taiwan

Other Decks in Programming

Transcript

  1. > Denny Tsai / UIT, LINE Taiwan Go-ing GraphQL in

    LINE SPOT API Gateway for Microservices
  2. GitHub API v3 (REST API) GraphQL vs REST https://api.github.com/repos/golang/go/issues [

    { "url": "https://api.github.com/repos/golang/go/issues/31459", "number": 31459, "title": "cmd/link: Apple's symbols tool unable to read DWARF data from c-archive go.o", "user": { "login": "tmm1", "avatar_url": "https://avatars2.githubusercontent.com/u/2567?v=4", }, "state": "open" }, { "url": "https://api.github.com/repos/golang/go/issues/31458", "number": 31458, "title": "cmd/go: mod meta tag causes infinite loop in GOPROXY", "user": { "login": "marwan-at-work", "avatar_url": "https://avatars0.githubusercontent.com/u/16294261?v=4",
  3. GitHub API v4 (GraphQL API) GraphQL vs REST Add your

    text here Whatever it is you want to message your friend, you will find the sticker that expresses your feelings best, like nothing else available in the market. Add your text here Whatever it is you want to message your friend, you will find the sticker that expresses your feelings best, like nothing else available in the market. { repository( owner: "golang" name: "go" ) { name issues( first: 2 orderBy: { field: CREATED_AT direction: DESC } ) { totalCount nodes { number title } } } } { "data": { "repository": { "name": "go", "issues": { "totalCount": 30761, "nodes": [ { "number": 31459, "title": "cmd/link: Apple's symbols tool ..." }, { "number": 31458, "title": "cmd/go: mod meta tag causes ..." } ] } } } }
  4. Define Schema with SDL Create a schema type Query {

    posts: [Post] post(id: Int!): Post } type Post { id: Int! title: String! body: String! }
  5. Generated Models Generated models type Post struct { ID int

    `json:"id"` Title string `json:"title"` Body string `json:"body"` }
  6. Generated Resolver Interface Resolver Interface type QueryResolver interface { Posts(ctx

    context.Context) ([]*Post, error) Post(ctx context.Context, id int) (*Post, error) }
  7. Implement Resolvers Resolvers type Resolver struct{} func (r *Resolver) Query()

    QueryResolver { return &queryResolver{r} } type queryResolver struct{ *Resolver } func (r *queryResolver) Posts(ctx context.Context) ([]*Post, error) { panic("not implemented") } func (r *queryResolver) Post(ctx context.Context, id int) (*Post, error) { panic("not implemented") }