Slide 1

Slide 1 text

2019 DevDay Go-Ing GraphQL in LINE SPOT - API Gateway for Microservices > Chih-Chiang Tsai (Denny) > LINE Taiwan UIT Software Engineer

Slide 2

Slide 2 text

Agenda > About Me > API Gateway & GraphQL > The State of GraphQL x Go

Slide 3

Slide 3 text

About Me Role Front-End Team LINE SPOT From LINE Taiwan

Slide 4

Slide 4 text

LINE SPOT Location-Based Points of Interests and Services >date/november 20-21 >place/grand nikko tokyo

Slide 5

Slide 5 text

API Gateway

Slide 6

Slide 6 text

Clients to Microservices

Slide 7

Slide 7 text

Clients to API Gateway

Slide 8

Slide 8 text

GraphQL

Slide 9

Slide 9 text

What is GraphQL Single Endpoint (HTTP) Typed Schema Transport Agnostic Consumer Centric Data Graph

Slide 10

Slide 10 text

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", },

Slide 11

Slide 11 text

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 ..." } ] } } } }

Slide 12

Slide 12 text

GraphQL x Go

Slide 13

Slide 13 text

Development Approaches Schema First Code First

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Define Schema with SDL Create a schema type Query { posts: [Post] post(id: Int!): Post } type Post { id: Int! title: String! body: String! }

Slide 17

Slide 17 text

Generated Resolver Interface Resolver Interface type QueryResolver interface { Posts(ctx context.Context) ([]*Post, error) Post(ctx context.Context, id int) (*Post, error) }

Slide 18

Slide 18 text

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") }

Slide 19

Slide 19 text

Generated Models Generated models type Post struct { ID int `json:"id"` Title string `json:"title"` Body string `json:"body"` }

Slide 20

Slide 20 text

Create a Server c := Config{ Resolvers: &Resolver{} } http.Handle("/graphql", handler.GraphQL(NewExecutableSchema(c))

Slide 21

Slide 21 text

Thanks!