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

Go + GraphQL @ newmo

Go + GraphQL @ newmo

Yuki Ito

May 22, 2024
Tweet

More Decks by Yuki Ito

Other Decks in Programming

Transcript

  1. GraphQL - without Federation type Driver { id: ID! name:

    String! } type Vehicle { id: ID! driverId: String! }
  2. GraphQL - with Aggregation (BFF) type Driver { id: ID!

    name: String! vehicles: [Vehicle!]! }
  3. 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!]! } +
  4. gqlgen type QueryResolver interface { Drivers(ctx context.Context) ([]*Driver, error) }

    type Driver struct { ID string `json:"id"` Name string `json:"name"` }
  5. 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
  6. Custom Validation Directives input CreateDriverInput { name: String! @validateString(minLen: 1)

    } type CreateDriverInput struct { Name string `json:"name" validate:"min=1"` }
  7. 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) }
  8. 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
  9. 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.