Slide 1

Slide 1 text

Go + GraphQL @ newmo @yuki.ito

Slide 2

Slide 2 text

newmo Architect Google Cloud Champion Innovator Modern Architecture / Serverless App Development Yuki Ito @mrno110

Slide 3

Slide 3 text

Agenda ɾAPI Architecture ɾGraphQL Code Generation for Go ɾModular Monolith GraphQL Server

Slide 4

Slide 4 text

Agenda ɾAPI Architecture ɾGraphQL Code Generation for Go ɾModular Monolith GraphQL Server

Slide 5

Slide 5 text

GraphQL API Server

Slide 6

Slide 6 text

Why GraphQL? ✅ Ecosystem ✅ Federation ✅ Declarative

Slide 7

Slide 7 text

Why GraphQL? ✅ Ecosystem ✅ Federation ✅ Declarative

Slide 8

Slide 8 text

GraphQL - without Federation

Slide 9

Slide 9 text

GraphQL - without Federation type Driver { id: ID! name: String! } type Vehicle { id: ID! driverId: String! }

Slide 10

Slide 10 text

GraphQL - without Federation ❌ Round Trips ❌ Aggregation Logics reside Web/Mobile side

Slide 11

Slide 11 text

GraphQL - with Aggregation (BFF)

Slide 12

Slide 12 text

GraphQL - with Aggregation (BFF) type Driver { id: ID! name: String! vehicles: [Vehicle!]! }

Slide 13

Slide 13 text

GraphQL - with Aggregation (BFF) ❌ Initiative ❌ Independence ❌ Autonomy

Slide 14

Slide 14 text

GraphQL - Federation

Slide 15

Slide 15 text

GraphQL - Federation type Driver @key(fields: "id") { id: ID! name: String! } type Driver @key(fields: "id") { id: ID! vehicles: [Vehicle!]! } type Vehicle { id: ID! } type Driver { id: ID! name: String! vehicles: [Vehicle!]! } +

Slide 16

Slide 16 text

GraphQL - Federation API Gateway Vehicle GraphQL GraphQL Federation (Apollo Router) Driver GraphQL Platfrom Business

Slide 17

Slide 17 text

gRPC

Slide 18

Slide 18 text

Why GraphQL? ✅ Ecosystem ✅ Federation ✅ Declarative

Slide 19

Slide 19 text

Agenda ɾAPI Architecture ɾGraphQL Code Generation for Go ɾModular Monolith GraphQL Server

Slide 20

Slide 20 text

Agenda ɾAPI Architecture ɾGraphQL Code Generation for Go ɾModular Monolith GraphQL Server

Slide 21

Slide 21 text

gqlgen https://gqlgen.com/

Slide 22

Slide 22 text

gqlgen type Query { drivers: [Driver!]! } type Driver { id: ID! name: String! }

Slide 23

Slide 23 text

gqlgen type QueryResolver interface { Drivers(ctx context.Context) ([]*Driver, error) } type Driver struct { ID string `json:"id"` Name string `json:"name"` }

Slide 24

Slide 24 text

gqlgen - Plugin https://gqlgen.com/reference/plugins/

Slide 25

Slide 25 text

Custom Validation Directives """ @validateString specifies constraints on an String/ID field or argument. This directive aims to be mainly used for generating validation logic for programming languages. """ directive @validateString( """ 'const' specifies that the value must be equal to the specified string. """ const: String """ 'len' specifies that the value must have the specified length. """ len: Int """ 'minLen' specifies that the value must have at least the specified length. """ minLen: Int """ 'maxLen' specifies that the value must have at most the specified length. """ maxLen: Int

Slide 26

Slide 26 text

Custom Validation Directives input CreateDriverInput { name: String! @validateString(minLen: 1) } type CreateDriverInput struct { Name string `json:"name" validate:"min=1"` }

Slide 27

Slide 27 text

Custom Validation Directives func (r *mutationResolver) CreateDriver(ctx context.Context, input CreateDriverInput) (//...) { if err := r.validator.Struct(input); err != nil { return nil, err } return r.resolver.CreateDriver(ctx, input) }

Slide 28

Slide 28 text

newmo ❤ oss https://github.com/newmo-oss/graphql-codegen-plugin-typescript-react-apollo

Slide 29

Slide 29 text

Agenda ɾAPI Architecture ɾGraphQL Code Generation for Go ɾModular Monolith GraphQL Server

Slide 30

Slide 30 text

Agenda ɾAPI Architecture ɾGraphQL Code Generation for Go ɾModular Monolith GraphQL Server

Slide 31

Slide 31 text

Go Components

Slide 32

Slide 32 text

Modular Monolith Almost all the cases where I've heard of a system that was built as a microservice system from scratch, it has ended up in serious trouble. ... you shouldn't start a new project with microservices, even if you're sure your application will be big enough to make it worthwhile. MonolithFirst Martin Fowler https://martinfowler.com/bliki/MonolithFirst.html

Slide 33

Slide 33 text

Modular Monolith ... splitting applications into independently deployable microservices is not without its challenges, some of which directly contradict the bene fi ts. Towards Modern Development of Cloud Applications Google (ServiceWeaver) https://dl.acm.org/doi/10.1145/3593856.3595909 ... Write monolithic applications that are modularized into logically distinct components.

Slide 34

Slide 34 text

GraphQL - Federation

Slide 35

Slide 35 text

Agenda ɾAPI Architecture ɾGraphQL Code Generation for Go ɾModular Monolith GraphQL Server

Slide 36

Slide 36 text

We are Hiring!!!