SlideShare a Scribd company logo
1 of 22
GraphQL API
Gateway
Go code generation isn’t frightful.
Yaroslav Mytso
Software engineer at EGT Ukraine
Service 1
(GRPC API)
Service 2
(GRPC API)
Service 3
(GRPC API)
Service N
(GRPC API)
Front-end
X
X
X
X
API
Gateway
Service 1
(GRPC API)
Service 2
(GRPC API)
Service 3
(GRPC API)
Service N
(GRPC API)
Front-end
{
user(id: «1») {
name
}
dog(name: «A»){
nick
}
}
{
«user»: {
«name»: «UserName»
},
«dog»: {
«nick»: «Bobby»
}
}
Type: User
Type: Pet
Type: String
Type: String
Type: Query
GraphQL → GRPC Proxy writing process
GRPC Message
GraphQL
Output Object
GraphQL
Input Object
GRPC Service
GraphQL
Fields Array
GRPC Enum
GraphQL
Enum
Input Object
unmarshaler+
GRPC
Method
Method
Resolver
Message in .proto file VS Message in GraphQL Schema
message A {
int32 someField = 1;
int64 someAnotherField = 2;
string andAnotherOne = 3;
}
var GQLA = graphql.NewObject(graphql.ObjectConfig{
Name: "A",
Fields: graphql.Fields{
"someField": &graphql.Field{
Name: "someField",
Type: graphql.Int,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
switch src := p.Source.(type) {
case A:
return src.SomeField, nil
case *A:
return src.SomeField, nil
}
return nil, nil
},
},
"someAnotherField": &graphql.Field{
Name: "someAnotherField",
Type: graphql.Int,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
switch src := p.Source.(type) {
case A:
return src.SomeAnotherField, nil
case *A:
return src.SomeAnotherField, nil
}
return nil, nil
},
},
"andAnotherOne": &graphql.Field{
Name: "andAnotherOne",
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
switch src := p.Source.(type) {
case A:
return src.AndAnotherOne, nil
case *A:
return src.AndAnotherOne, nil
}
return nil, nil
},
},
},
})
😞
protoc-gen-gogoopsee
(gogo plugin)
http://github.com/opsee/protobuf/
*.proto gogo
stdin
stdout
GRPC Client
GRPC Client Tests
GoGo code generation process
plugin 1plugin 1 plugin 2 plugin N
protoc-gen-gogoopsee
GRPC Message
GraphQL
Output Object
GraphQL
Input Object
GRPC Service
GraphQL
Fields Array
GRPC Enum
GraphQL
Enum
Input Object
unmarshaler+
GRPC
Method
Field
Resolver
X
X
X
p.P(`»`, field.GetName(), `": &`, graphQLPkg.Use(), `.Field{`)
p.In()
p.P(`Type: `, p.graphQLType(message, field, graphQLPkg, schemaPkg), `,`)
p.P(`Description: `, fieldGQL, `,`)
p.P(`Resolve: func(p `, graphQLPkg.Use(), `.ResolveParams) (interface{}, error) {`)
p.In()
p.P(`return nil, nil`)
p.Out()
p.P(`}}`)
p.Out()
fmt.Println() generated code
«{{$field.Name}}»: {{gqlPkg}}.Field{
Type: {{call $field.Type}},
Description: {{$field.Description}},
Resolve: func(p {{gqlPkg}}.ResolveParams) (interface{}, error) {
return nil, nil
}
}
Generate code using
text/template
GoGo plugin problems
• Only two files in output
• Generator knows about only one .proto file and can’t
make composition
• Hard to debug
• Option-based configuration
.proto files parser
generate.yaml
vendor_path: «./vendor»
paths:
- «$GOPATH/src»
- «./vendor»
proto_files:
- path : «./a.proto»
- …
- path: «./b.proto»
schema:
Query:
- field: «a»
type: «SERVICE»
- field: «b»
type: «SERVICE»
Parser
Query {
a : AService,
b: BService,
}
AService {
meth1(req:Req) : MethResp,
meth2(req:Req) : SomeRes,
}
BService {
meth1(req:Req) : MethResp,
}
a.proto b.proto
Template
schema.go
./services/a.go
./services/b.go
proto2gql
Too heavy template
Generator responsibilities
.proto files
GraphQL schema
Generator responsibilities
.proto files
GraphQL schema
swagger files
Custom .proto files parser
generate.yaml
vendor_path: «./vendor»
paths:
- «$GOPATH/src»
- «./vendor»
proto_files:
- path : «./a.proto»
- …
- path: «./b.proto»
schema:
Query:
- field: «a»
type: «SERVICE»
- field: «b»
type: «SERVICE»
Query {
a : AService,
b: BService,
}
AService {
meth1(req:Req) : MethResp,
meth2(req:Req) : SomeRes,
}
BService {
meth1(req:Req) : MethResp,
}
Parser
a.proto b.proto
Template
schema.go
./services/a.go
./services/b.go
Normalizing data
generate.yaml
vendor_path: «./vendor»
paths:
- «$GOPATH/src»
- «./vendor»
proto_files:
- path : «./a.proto»
- …
- path: «./b.proto»
schema:
Query:
- field: «a»
type: «SERVICE»
- field: «b»
type: «SERVICE»
Query {
a : AService,
b: BService,
}
AService {
meth1(req:Req) : MethResp,
meth2(req:Req) : SomeRes,
}
BService {
meth1(req:Req) : MethResp,
}
.proto
parser
a.proto
b.proto
Template
schema.go
./services/a.go
./services/b.go
swagger
Parser
data
normalizer
data
normalizer
swagger1.yml
swagger2.yml
generate.yaml
vendor_path: «./»
graphql:
schemas:
…
proto2gql:
proto_files:
- …
swagger2gql:
swagger_files:
- …
graphql plugin
(knows how to generate graphql
schema based on own DTO’s)
proto2gql plugin
(knows how to convert info about
*.proto file into graphql DTO’s)
proto2gql
swagger2gql plugin
(knows how to convert info
swagger file into graphql DTO’s)
Plugins
github.com/saturn4er/proto2gql
Conclusions
• Use templates in code generation
• Prepare data for templates in case of a possibility
of some other data-source
• Choose toolchain that will not frame you
Questions?
Yaroslav Mytso
yaroslav.mitso@egt-ua.com
github.com/saturn4er

More Related Content

What's hot

Debugging Applications with GNU Debugger
Debugging Applications with GNU DebuggerDebugging Applications with GNU Debugger
Debugging Applications with GNU DebuggerPriyank Kapadia
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoRodolfo Carvalho
 
Andriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsAndriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsOWASP Kyiv
 
Compiling Under Linux
Compiling Under LinuxCompiling Under Linux
Compiling Under LinuxPierreMASURE
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Jimmy Schementi
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Ovidiu Farauanu
 
Documenting an API written in Django Rest Framework
Documenting an API written in Django Rest FrameworkDocumenting an API written in Django Rest Framework
Documenting an API written in Django Rest Frameworksmirolo
 
PyCon Ukraine 2016: Maintaining a high load Python project for newcomers
PyCon Ukraine 2016: Maintaining a high load Python project for newcomersPyCon Ukraine 2016: Maintaining a high load Python project for newcomers
PyCon Ukraine 2016: Maintaining a high load Python project for newcomersViach Kakovskyi
 
GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005Saleem Ansari
 
How to easily find the optimal solution without exhaustive search using Genet...
How to easily find the optimal solution without exhaustive search using Genet...How to easily find the optimal solution without exhaustive search using Genet...
How to easily find the optimal solution without exhaustive search using Genet...Viach Kakovskyi
 
Java 11 - Keeping the Java Release Train on the Right Track
Java 11 - Keeping the Java Release Train on the Right TrackJava 11 - Keeping the Java Release Train on the Right Track
Java 11 - Keeping the Java Release Train on the Right TrackC4Media
 
Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo Yu-Shuan Hsieh
 

What's hot (20)

ActiveDoc
ActiveDocActiveDoc
ActiveDoc
 
Debugging Applications with GNU Debugger
Debugging Applications with GNU DebuggerDebugging Applications with GNU Debugger
Debugging Applications with GNU Debugger
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX Go
 
Andriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsAndriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tips
 
Invoke Dynamic
Invoke DynamicInvoke Dynamic
Invoke Dynamic
 
Golang
GolangGolang
Golang
 
Compiling Under Linux
Compiling Under LinuxCompiling Under Linux
Compiling Under Linux
 
Gccgdb
GccgdbGccgdb
Gccgdb
 
Gnu debugger
Gnu debuggerGnu debugger
Gnu debugger
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011
 
Golang for OO Programmers
Golang for OO ProgrammersGolang for OO Programmers
Golang for OO Programmers
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
 
Documenting an API written in Django Rest Framework
Documenting an API written in Django Rest FrameworkDocumenting an API written in Django Rest Framework
Documenting an API written in Django Rest Framework
 
PyCon Ukraine 2016: Maintaining a high load Python project for newcomers
PyCon Ukraine 2016: Maintaining a high load Python project for newcomersPyCon Ukraine 2016: Maintaining a high load Python project for newcomers
PyCon Ukraine 2016: Maintaining a high load Python project for newcomers
 
GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005
 
GCC compiler
GCC compilerGCC compiler
GCC compiler
 
How to easily find the optimal solution without exhaustive search using Genet...
How to easily find the optimal solution without exhaustive search using Genet...How to easily find the optimal solution without exhaustive search using Genet...
How to easily find the optimal solution without exhaustive search using Genet...
 
Java 11 - Keeping the Java Release Train on the Right Track
Java 11 - Keeping the Java Release Train on the Right TrackJava 11 - Keeping the Java Release Train on the Right Track
Java 11 - Keeping the Java Release Train on the Right Track
 
Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo
 
Usage of GDB
Usage of GDBUsage of GDB
Usage of GDB
 

Similar to Graph ql api gateway

GraphQL IN Golang
GraphQL IN GolangGraphQL IN Golang
GraphQL IN GolangBo-Yi Wu
 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talkdesistartups
 
Build microservice with gRPC in golang
Build microservice with gRPC in golangBuild microservice with gRPC in golang
Build microservice with gRPC in golangTing-Li Chou
 
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...apidays
 
To GO or not to GO
To GO or not to GOTo GO or not to GO
To GO or not to GOsuperstas88
 
Codified PostgreSQL Schema
Codified PostgreSQL SchemaCodified PostgreSQL Schema
Codified PostgreSQL SchemaSean Chittenden
 
Nikita Galkin "Looking for the right tech stack for GraphQL application"
Nikita Galkin "Looking for the right tech stack for GraphQL application"Nikita Galkin "Looking for the right tech stack for GraphQL application"
Nikita Galkin "Looking for the right tech stack for GraphQL application"Fwdays
 
Implementing OpenAPI and GraphQL services with gRPC
Implementing OpenAPI and GraphQL services with gRPCImplementing OpenAPI and GraphQL services with gRPC
Implementing OpenAPI and GraphQL services with gRPCTim Burks
 
Usable APIs at Scale
Usable APIs at ScaleUsable APIs at Scale
Usable APIs at ScaleTim Burks
 
GraphQL the holy contract between client and server
GraphQL the holy contract between client and serverGraphQL the holy contract between client and server
GraphQL the holy contract between client and serverPavel Chertorogov
 
Tutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPAndrew Rota
 
Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io
 
GDG Cloud Taipei meetup #50 - Build go kit microservices at kubernetes with ...
GDG Cloud Taipei meetup #50 - Build go kit microservices at kubernetes  with ...GDG Cloud Taipei meetup #50 - Build go kit microservices at kubernetes  with ...
GDG Cloud Taipei meetup #50 - Build go kit microservices at kubernetes with ...KAI CHU CHUNG
 
Azure for SharePoint Developers - Workshop - Part 2: Azure Functions
Azure for SharePoint Developers - Workshop - Part 2: Azure FunctionsAzure for SharePoint Developers - Workshop - Part 2: Azure Functions
Azure for SharePoint Developers - Workshop - Part 2: Azure FunctionsBob German
 
20170624 GraphQL Presentation
20170624 GraphQL Presentation20170624 GraphQL Presentation
20170624 GraphQL PresentationMartin Heidegger
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applicationsRoman Podoliaka
 
Geospatial web services using little-known GDAL features and modern Perl midd...
Geospatial web services using little-known GDAL features and modern Perl midd...Geospatial web services using little-known GDAL features and modern Perl midd...
Geospatial web services using little-known GDAL features and modern Perl midd...Ari Jolma
 
gRPC or Rest, why not both?
gRPC or Rest, why not both?gRPC or Rest, why not both?
gRPC or Rest, why not both?Mohammad Murad
 
Writing an Ostinato Protocol Builder [FOSDEM 2021]
Writing an Ostinato Protocol Builder [FOSDEM 2021]Writing an Ostinato Protocol Builder [FOSDEM 2021]
Writing an Ostinato Protocol Builder [FOSDEM 2021]pstavirs
 

Similar to Graph ql api gateway (20)

GraphQL IN Golang
GraphQL IN GolangGraphQL IN Golang
GraphQL IN Golang
 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talk
 
Build microservice with gRPC in golang
Build microservice with gRPC in golangBuild microservice with gRPC in golang
Build microservice with gRPC in golang
 
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
 
To GO or not to GO
To GO or not to GOTo GO or not to GO
To GO or not to GO
 
Go react codelab
Go react codelabGo react codelab
Go react codelab
 
Codified PostgreSQL Schema
Codified PostgreSQL SchemaCodified PostgreSQL Schema
Codified PostgreSQL Schema
 
Nikita Galkin "Looking for the right tech stack for GraphQL application"
Nikita Galkin "Looking for the right tech stack for GraphQL application"Nikita Galkin "Looking for the right tech stack for GraphQL application"
Nikita Galkin "Looking for the right tech stack for GraphQL application"
 
Implementing OpenAPI and GraphQL services with gRPC
Implementing OpenAPI and GraphQL services with gRPCImplementing OpenAPI and GraphQL services with gRPC
Implementing OpenAPI and GraphQL services with gRPC
 
Usable APIs at Scale
Usable APIs at ScaleUsable APIs at Scale
Usable APIs at Scale
 
GraphQL the holy contract between client and server
GraphQL the holy contract between client and serverGraphQL the holy contract between client and server
GraphQL the holy contract between client and server
 
Tutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHP
 
Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and Golang
 
GDG Cloud Taipei meetup #50 - Build go kit microservices at kubernetes with ...
GDG Cloud Taipei meetup #50 - Build go kit microservices at kubernetes  with ...GDG Cloud Taipei meetup #50 - Build go kit microservices at kubernetes  with ...
GDG Cloud Taipei meetup #50 - Build go kit microservices at kubernetes with ...
 
Azure for SharePoint Developers - Workshop - Part 2: Azure Functions
Azure for SharePoint Developers - Workshop - Part 2: Azure FunctionsAzure for SharePoint Developers - Workshop - Part 2: Azure Functions
Azure for SharePoint Developers - Workshop - Part 2: Azure Functions
 
20170624 GraphQL Presentation
20170624 GraphQL Presentation20170624 GraphQL Presentation
20170624 GraphQL Presentation
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applications
 
Geospatial web services using little-known GDAL features and modern Perl midd...
Geospatial web services using little-known GDAL features and modern Perl midd...Geospatial web services using little-known GDAL features and modern Perl midd...
Geospatial web services using little-known GDAL features and modern Perl midd...
 
gRPC or Rest, why not both?
gRPC or Rest, why not both?gRPC or Rest, why not both?
gRPC or Rest, why not both?
 
Writing an Ostinato Protocol Builder [FOSDEM 2021]
Writing an Ostinato Protocol Builder [FOSDEM 2021]Writing an Ostinato Protocol Builder [FOSDEM 2021]
Writing an Ostinato Protocol Builder [FOSDEM 2021]
 

Recently uploaded

Adsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptAdsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptjigup7320
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsVIEW
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxkalpana413121
 
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTUUNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTUankushspencer015
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...archanaece3
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisDr.Costas Sachpazis
 
Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualBalamuruganV28
 
engineering chemistry power point presentation
engineering chemistry  power point presentationengineering chemistry  power point presentation
engineering chemistry power point presentationsj9399037128
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...Amil baba
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailingAshishSingh1301
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdfAlexander Litvinenko
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxKarpagam Institute of Teechnology
 
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and ToolsMaximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Toolssoginsider
 
History of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationHistory of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationEmaan Sharma
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1T.D. Shashikala
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxMustafa Ahmed
 
Insurance management system project report.pdf
Insurance management system project report.pdfInsurance management system project report.pdf
Insurance management system project report.pdfKamal Acharya
 
Basics of Relay for Engineering Students
Basics of Relay for Engineering StudentsBasics of Relay for Engineering Students
Basics of Relay for Engineering Studentskannan348865
 
electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.benjamincojr
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfSkNahidulIslamShrabo
 

Recently uploaded (20)

Adsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptAdsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) ppt
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, Functions
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTUUNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
 
Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manual
 
engineering chemistry power point presentation
engineering chemistry  power point presentationengineering chemistry  power point presentation
engineering chemistry power point presentation
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailing
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and ToolsMaximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
 
History of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationHistory of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & Modernization
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
Insurance management system project report.pdf
Insurance management system project report.pdfInsurance management system project report.pdf
Insurance management system project report.pdf
 
Basics of Relay for Engineering Students
Basics of Relay for Engineering StudentsBasics of Relay for Engineering Students
Basics of Relay for Engineering Students
 
electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdf
 

Graph ql api gateway

  • 1. GraphQL API Gateway Go code generation isn’t frightful. Yaroslav Mytso Software engineer at EGT Ukraine
  • 2. Service 1 (GRPC API) Service 2 (GRPC API) Service 3 (GRPC API) Service N (GRPC API) Front-end X X X X
  • 3. API Gateway Service 1 (GRPC API) Service 2 (GRPC API) Service 3 (GRPC API) Service N (GRPC API) Front-end
  • 4. { user(id: «1») { name } dog(name: «A»){ nick } } { «user»: { «name»: «UserName» }, «dog»: { «nick»: «Bobby» } } Type: User Type: Pet Type: String Type: String Type: Query
  • 5. GraphQL → GRPC Proxy writing process GRPC Message GraphQL Output Object GraphQL Input Object GRPC Service GraphQL Fields Array GRPC Enum GraphQL Enum Input Object unmarshaler+ GRPC Method Method Resolver
  • 6. Message in .proto file VS Message in GraphQL Schema message A { int32 someField = 1; int64 someAnotherField = 2; string andAnotherOne = 3; } var GQLA = graphql.NewObject(graphql.ObjectConfig{ Name: "A", Fields: graphql.Fields{ "someField": &graphql.Field{ Name: "someField", Type: graphql.Int, Resolve: func(p graphql.ResolveParams) (interface{}, error) { switch src := p.Source.(type) { case A: return src.SomeField, nil case *A: return src.SomeField, nil } return nil, nil }, }, "someAnotherField": &graphql.Field{ Name: "someAnotherField", Type: graphql.Int, Resolve: func(p graphql.ResolveParams) (interface{}, error) { switch src := p.Source.(type) { case A: return src.SomeAnotherField, nil case *A: return src.SomeAnotherField, nil } return nil, nil }, }, "andAnotherOne": &graphql.Field{ Name: "andAnotherOne", Type: graphql.String, Resolve: func(p graphql.ResolveParams) (interface{}, error) { switch src := p.Source.(type) { case A: return src.AndAnotherOne, nil case *A: return src.AndAnotherOne, nil } return nil, nil }, }, }, }) 😞
  • 8. *.proto gogo stdin stdout GRPC Client GRPC Client Tests GoGo code generation process plugin 1plugin 1 plugin 2 plugin N
  • 9. protoc-gen-gogoopsee GRPC Message GraphQL Output Object GraphQL Input Object GRPC Service GraphQL Fields Array GRPC Enum GraphQL Enum Input Object unmarshaler+ GRPC Method Field Resolver X X X
  • 10. p.P(`»`, field.GetName(), `": &`, graphQLPkg.Use(), `.Field{`) p.In() p.P(`Type: `, p.graphQLType(message, field, graphQLPkg, schemaPkg), `,`) p.P(`Description: `, fieldGQL, `,`) p.P(`Resolve: func(p `, graphQLPkg.Use(), `.ResolveParams) (interface{}, error) {`) p.In() p.P(`return nil, nil`) p.Out() p.P(`}}`) p.Out() fmt.Println() generated code
  • 11. «{{$field.Name}}»: {{gqlPkg}}.Field{ Type: {{call $field.Type}}, Description: {{$field.Description}}, Resolve: func(p {{gqlPkg}}.ResolveParams) (interface{}, error) { return nil, nil } } Generate code using text/template
  • 12. GoGo plugin problems • Only two files in output • Generator knows about only one .proto file and can’t make composition • Hard to debug • Option-based configuration
  • 13. .proto files parser generate.yaml vendor_path: «./vendor» paths: - «$GOPATH/src» - «./vendor» proto_files: - path : «./a.proto» - … - path: «./b.proto» schema: Query: - field: «a» type: «SERVICE» - field: «b» type: «SERVICE» Parser Query { a : AService, b: BService, } AService { meth1(req:Req) : MethResp, meth2(req:Req) : SomeRes, } BService { meth1(req:Req) : MethResp, } a.proto b.proto Template schema.go ./services/a.go ./services/b.go proto2gql
  • 17. Custom .proto files parser generate.yaml vendor_path: «./vendor» paths: - «$GOPATH/src» - «./vendor» proto_files: - path : «./a.proto» - … - path: «./b.proto» schema: Query: - field: «a» type: «SERVICE» - field: «b» type: «SERVICE» Query { a : AService, b: BService, } AService { meth1(req:Req) : MethResp, meth2(req:Req) : SomeRes, } BService { meth1(req:Req) : MethResp, } Parser a.proto b.proto Template schema.go ./services/a.go ./services/b.go
  • 18. Normalizing data generate.yaml vendor_path: «./vendor» paths: - «$GOPATH/src» - «./vendor» proto_files: - path : «./a.proto» - … - path: «./b.proto» schema: Query: - field: «a» type: «SERVICE» - field: «b» type: «SERVICE» Query { a : AService, b: BService, } AService { meth1(req:Req) : MethResp, meth2(req:Req) : SomeRes, } BService { meth1(req:Req) : MethResp, } .proto parser a.proto b.proto Template schema.go ./services/a.go ./services/b.go swagger Parser data normalizer data normalizer swagger1.yml swagger2.yml
  • 19. generate.yaml vendor_path: «./» graphql: schemas: … proto2gql: proto_files: - … swagger2gql: swagger_files: - … graphql plugin (knows how to generate graphql schema based on own DTO’s) proto2gql plugin (knows how to convert info about *.proto file into graphql DTO’s) proto2gql swagger2gql plugin (knows how to convert info swagger file into graphql DTO’s) Plugins
  • 21. Conclusions • Use templates in code generation • Prepare data for templates in case of a possibility of some other data-source • Choose toolchain that will not frame you