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

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

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

Chih-Chiang Tsai (Denny)
LINE Taiwan UIT Software Engineer
https://linedevday.linecorp.com/jp/2019/sessions/S2-19

LINE DevDay 2019

November 21, 2019
Tweet

More Decks by LINE DevDay 2019

Other Decks in Technology

Transcript

  1. 2019 DevDay Go-Ing GraphQL in LINE SPOT - API Gateway

    for Microservices > Chih-Chiang Tsai (Denny) > LINE Taiwan UIT Software Engineer
  2. GitHub API v3 (REST 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. 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 Resolver Interface Resolver Interface type QueryResolver interface { Posts(ctx

    context.Context) ([]*Post, error) Post(ctx context.Context, id int) (*Post, error) }
  6. 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") }
  7. Generated Models Generated models type Post struct { ID int

    `json:"id"` Title string `json:"title"` Body string `json:"body"` }