SlideShare a Scribd company logo
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

ActiveDoc
ActiveDocActiveDoc
ActiveDoc
Ivan Nečas
 
Debugging Applications with GNU Debugger
Debugging Applications with GNU DebuggerDebugging Applications with GNU Debugger
Debugging Applications with GNU Debugger
Priyank 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 Go
Rodolfo Carvalho
 
Andriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsAndriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tips
OWASP Kyiv
 
Invoke Dynamic
Invoke DynamicInvoke Dynamic
Invoke Dynamic
Dmitry Buzdin
 
Golang
GolangGolang
Compiling Under Linux
Compiling Under LinuxCompiling Under Linux
Compiling Under Linux
PierreMASURE
 
Gccgdb
GccgdbGccgdb
Gccgdb
selva raj
 
Gnu debugger
Gnu debuggerGnu debugger
Gnu debugger
Gizem Çetin
 
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
Jimmy Schementi
 
Golang for OO Programmers
Golang for OO ProgrammersGolang for OO Programmers
Golang for OO Programmers
khalid Nowaf Almutiri
 
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 Framework
smirolo
 
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
Viach Kakovskyi
 
GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005
Saleem Ansari
 
GCC compiler
GCC compilerGCC compiler
GCC compiler
Anil Pokhrel
 
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 Track
C4Media
 
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
 
Usage of GDB
Usage of GDBUsage of GDB
Usage of GDB
Jongseok Choi
 

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 Golang
Bo-Yi Wu
 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talk
desistartups
 
Build microservice with gRPC in golang
Build microservice with gRPC in golangBuild microservice with gRPC in golang
Build microservice with gRPC in golang
Ting-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 GO
superstas88
 
Go react codelab
Go react codelabGo react codelab
Managing gRPC Services using Kong KONNECT and the KONG API Gateway
Managing gRPC Services using Kong KONNECT and the KONG API GatewayManaging gRPC Services using Kong KONNECT and the KONG API Gateway
Managing gRPC Services using Kong KONNECT and the KONG API Gateway
João Esperancinha
 
Codified PostgreSQL Schema
Codified PostgreSQL SchemaCodified PostgreSQL Schema
Codified PostgreSQL Schema
Sean 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 gRPC
Tim Burks
 
Usable APIs at Scale
Usable APIs at ScaleUsable APIs at Scale
Usable APIs at Scale
Tim 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 server
Pavel 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 PHP
Andrew 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 Golang
Mender.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 Functions
Bob German
 
20170624 GraphQL Presentation
20170624 GraphQL Presentation20170624 GraphQL Presentation
20170624 GraphQL Presentation
Martin Heidegger
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applications
Roman 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
 

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
 
Managing gRPC Services using Kong KONNECT and the KONG API Gateway
Managing gRPC Services using Kong KONNECT and the KONG API GatewayManaging gRPC Services using Kong KONNECT and the KONG API Gateway
Managing gRPC Services using Kong KONNECT and the KONG API Gateway
 
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?
 

Recently uploaded

New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
PuktoonEngr
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 

Recently uploaded (20)

New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 

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