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

Be4518b119b8eb017625e0ead20f8fe7?s=128

LINE DevDay 2019

November 21, 2019
Tweet

Transcript

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

    for Microservices > Chih-Chiang Tsai (Denny) > LINE Taiwan UIT Software Engineer
  2. Agenda > About Me > API Gateway & GraphQL >

    The State of GraphQL x Go
  3. About Me Role Front-End Team LINE SPOT From LINE Taiwan

  4. LINE SPOT Location-Based Points of Interests and Services >date/november 20-21

    >place/grand nikko tokyo
  5. API Gateway

  6. Clients to Microservices

  7. Clients to API Gateway

  8. GraphQL

  9. What is GraphQL Single Endpoint (HTTP) Typed Schema Transport Agnostic

    Consumer Centric Data Graph
  10. 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", },
  11. 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 ..." } ] } } } }
  12. GraphQL x Go

  13. Development Approaches Schema First Code First

  14. Go GraphQL Libraries github.com/graphql-go/graphql code first github.com/99designs/gqlgen schema + codegen

    github.com/graph-gophers/graphql-go schema first
  15. Go GraphQL Libraries github.com/graphql-go/graphql code first github.com/99designs/gqlgen schema + codegen

    github.com/graph-gophers/graphql-go schema first
  16. Define Schema with SDL Create a schema type Query {

    posts: [Post] post(id: Int!): Post } type Post { id: Int! title: String! body: String! }
  17. Generated Resolver Interface Resolver Interface type QueryResolver interface { Posts(ctx

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

    `json:"id"` Title string `json:"title"` Body string `json:"body"` }
  20. Create a Server c := Config{ Resolvers: &Resolver{} } http.Handle("/graphql",

    handler.GraphQL(NewExecutableSchema(c))
  21. Thanks!