SlideShare a Scribd company logo
LoopBack4 and OASGraph
GraphQL in minutes!
By Mario Estrada
marioestradarosa@gmail.com
What is OASGraph?
Turns APIs described by OpenAPI specifications (OAS) into GraphQL
interfaces.



https://github.com/strongloop/oasgraph
What is LoopBack 4?
LoopBack 4 makes it easy to build modern applications that require
complex integrations.
• Fast, small, powerful, extensible core
• Generate real APIs with a single command
• Define your data and endpoints with OpenAPI
https://github.com/strongloop/loopback-next
Loopback 4 High Level Overview
LoopBack 4
DB
SOAP
REST
Open API specification
{ REST SERVER }
REST
OasGraph Integration Overview
LoopBack 4
OASGraph Library
Open API

Specification
GraphQL Schema
Express-graphql
REST
GraphQL
Let’s code !
INSTALLING LOOPBACK4
npm install -g @loopback/cli
Generating todo-list example
lb4 example todo-list
INSTALL OASGRAPH DEPENDENCY
npm install oasgraph —save
cd loopback4-example-todo-list
npm install express-graphql —save
Modify src/application.ts
options = Object.assign({}, {
rest: {
openApiSpec: {
servers: [{url:'http://localhost:3000'}],
}
}
});
Add the following code before the super(options); 

This will help OASGraph determine the URL for the resolver(s).
At runtime the OpenApi Spec parameter
OpenAPI Spec
options = Object.assign({}, {
rest: {
openApiSpec: {
servers: [{url:'http://
localhost:3000'}],
}
}
});
GraphQL Schema
"servers": [
{
"url": "http://localhost:3000/"
}
],
Resolver URL
Modify src/index.ts
Import dependencies
This will make the the express, express-graphql and oasgraph available.
const OASGraph = require('oasgraph');
const express = require('express');
const graphqlHTTP = require('express-graphql');
Modify src/index.ts
Create the Schema Object
Note that we are using the method getApiSpec from the LoopBack 4 rest server. This is the
magic, the OASGraph.createGraphQlSchema is converting it to a GraphQL Schema
automatically and accurately.
const {schema} = await
OASGraph.createGraphQlSchema(
app.restServer.getApiSpec(),
{
strict: false,
viewer: true,
addSubOperations: true,
sendOAuthTokeninQuery: false,
},
);
Note: This code will be wrapped inside a try/catch. And starts after line console.log(`Try ${url}/ping`);
LoopBack 4
OASGraph Library
Open API

Specification
Modify src/index.ts
Starts the GraphQL Server
With the GraphQL schema generated already, it is just a matter of starting the GraphQL
server in a specific port, in this case, we are using port 3001.
const myExpress = express();
myExpress.use('/graphql', graphqlHTTP(
{
schema: schema,
graphiql: true,
}
));
myExpress.listen(3001, () => {
console.log('OASGraph ready at http://localhost:3001/graphql');
});
Note: This code will be wrapped inside a try/catch.
OASGraph Library
GraphQL Schema
Express-graphql
Full code
src/index.ts
The following code, should placed after rest server has been initiated.

try {
const {schema} = await OASGraph.createGraphQlSchema(
app.restServer.getApiSpec(),
{
strict: false,
viewer: true,
addSubOperations: true,
sendOAuthTokeninQuery: false,
},
);
const myExpress = express();
myExpress.use('/graphql', graphqlHTTP({schema: schema, graphiql: true}));
myExpress.listen(3001, () => {
console.log('OASGraph ready at http://localhost:3001/graphql');
});
} catch (err) {
console.log('Error: ', err.message);
}
return app;

}
Now run the application
npm start
> node .
Server is running at http://[::1]:3000
OASGraph ready at http://localhost:3001/graphql
End point for GraphQL Server
Use GraphiQL tool
Open in browser at http://localhost:3001/graphql
GraphiQL Tool
http://localhost:3001/graphql
Thank you !
Visit http://v4.loopback.io

More Related Content

What's hot (20)

PDF
Building a Data Pipeline using Apache Airflow (on AWS / GCP)
Yohei Onishi
 
PDF
Building an analytics workflow using Apache Airflow
Yohei Onishi
 
PDF
Apache airflow
Purna Chander
 
ODP
Gatling - Stress test tool
Knoldus Inc.
 
PDF
Introducing Apache Airflow and how we are using it
Bruno Faria
 
PDF
Continuous performance management with Gatling
Radoslaw Smilgin
 
PDF
Apache Airflow
Sumit Maheshwari
 
PDF
Load test REST APIs using gatling
Jayaram Sankaranarayanan
 
PDF
Airflow Best Practises & Roadmap to Airflow 2.0
Kaxil Naik
 
PPTX
Apache Airflow Introduction
Liangjun Jiang
 
PPTX
Grails Plugin
guligala
 
PPTX
Where is my scalable api?
Altoros
 
PDF
ОЛЕГ МАЦЬКІВ «Crash course on Operator Framework» Lviv DevOps Conference 2019
UA DevOps Conference
 
PDF
Retrofit
bresiu
 
PPTX
Top 10 RxJs Operators in Angular
Jalpesh Vadgama
 
PDF
V8 javascript engine for フロントエンドデベロッパー
Taketoshi 青野健利
 
PDF
What's coming in Airflow 2.0? - NYC Apache Airflow Meetup
Kaxil Naik
 
PDF
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
Loiane Groner
 
PDF
FullStack Reativo com Spring WebFlux + Angular
Loiane Groner
 
PDF
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Loiane Groner
 
Building a Data Pipeline using Apache Airflow (on AWS / GCP)
Yohei Onishi
 
Building an analytics workflow using Apache Airflow
Yohei Onishi
 
Apache airflow
Purna Chander
 
Gatling - Stress test tool
Knoldus Inc.
 
Introducing Apache Airflow and how we are using it
Bruno Faria
 
Continuous performance management with Gatling
Radoslaw Smilgin
 
Apache Airflow
Sumit Maheshwari
 
Load test REST APIs using gatling
Jayaram Sankaranarayanan
 
Airflow Best Practises & Roadmap to Airflow 2.0
Kaxil Naik
 
Apache Airflow Introduction
Liangjun Jiang
 
Grails Plugin
guligala
 
Where is my scalable api?
Altoros
 
ОЛЕГ МАЦЬКІВ «Crash course on Operator Framework» Lviv DevOps Conference 2019
UA DevOps Conference
 
Retrofit
bresiu
 
Top 10 RxJs Operators in Angular
Jalpesh Vadgama
 
V8 javascript engine for フロントエンドデベロッパー
Taketoshi 青野健利
 
What's coming in Airflow 2.0? - NYC Apache Airflow Meetup
Kaxil Naik
 
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
Loiane Groner
 
FullStack Reativo com Spring WebFlux + Angular
Loiane Groner
 
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Loiane Groner
 

Similar to OASGraph LoopBack 4 Integration (20)

PDF
How easy (or hard) it is to monitor your graph ql service performance
Red Hat
 
PDF
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Roman Kirillov
 
PDF
GraphQL across the stack: How everything fits together
Sashko Stubailo
 
PDF
The GrapQL ecosystem
OlegsGabrusjonoks
 
PPT
Graphql presentation
Vibhor Grover
 
PDF
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
mfrancis
 
PPTX
Graph ql subscriptions on the jvm
Gerard Klijs
 
PDF
Cascading on starfish
Fei Dong
 
PDF
Graphql usage
Valentin Buryakov
 
PDF
What is new in java 8 concurrency
kshanth2101
 
ODP
Developingapiplug insforcs-151112204727-lva1-app6891
NetApp
 
PPTX
Java Libraries You Can’t Afford to Miss
Andres Almiray
 
PDF
Arquitecturas de microservicios - Medianet Software
Ernesto Hernández Rodríguez
 
PDF
GraphQL over REST at Reactathon 2018
Sashko Stubailo
 
PDF
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or Serverless
QAware GmbH
 
PPTX
Graph ql subscriptions through the looking glass
Gerard Klijs
 
PDF
GraphQL in Apache Sling - but isn't it the opposite of REST?
Bertrand Delacretaz
 
PDF
Angular for Java Enterprise Developers: Oracle Code One 2018
Loiane Groner
 
PDF
Boost your API with GraphQL
Jean-Francois James
 
PPTX
How to provide a GraphQL API - I want it that way
QAware GmbH
 
How easy (or hard) it is to monitor your graph ql service performance
Red Hat
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Roman Kirillov
 
GraphQL across the stack: How everything fits together
Sashko Stubailo
 
The GrapQL ecosystem
OlegsGabrusjonoks
 
Graphql presentation
Vibhor Grover
 
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
mfrancis
 
Graph ql subscriptions on the jvm
Gerard Klijs
 
Cascading on starfish
Fei Dong
 
Graphql usage
Valentin Buryakov
 
What is new in java 8 concurrency
kshanth2101
 
Developingapiplug insforcs-151112204727-lva1-app6891
NetApp
 
Java Libraries You Can’t Afford to Miss
Andres Almiray
 
Arquitecturas de microservicios - Medianet Software
Ernesto Hernández Rodríguez
 
GraphQL over REST at Reactathon 2018
Sashko Stubailo
 
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or Serverless
QAware GmbH
 
Graph ql subscriptions through the looking glass
Gerard Klijs
 
GraphQL in Apache Sling - but isn't it the opposite of REST?
Bertrand Delacretaz
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Loiane Groner
 
Boost your API with GraphQL
Jean-Francois James
 
How to provide a GraphQL API - I want it that way
QAware GmbH
 
Ad

Recently uploaded (20)

PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Ad

OASGraph LoopBack 4 Integration

  • 1. LoopBack4 and OASGraph GraphQL in minutes! By Mario Estrada [email protected]
  • 2. What is OASGraph? Turns APIs described by OpenAPI specifications (OAS) into GraphQL interfaces.
 
 https://github.com/strongloop/oasgraph What is LoopBack 4? LoopBack 4 makes it easy to build modern applications that require complex integrations. • Fast, small, powerful, extensible core • Generate real APIs with a single command • Define your data and endpoints with OpenAPI https://github.com/strongloop/loopback-next
  • 3. Loopback 4 High Level Overview LoopBack 4 DB SOAP REST Open API specification { REST SERVER } REST
  • 4. OasGraph Integration Overview LoopBack 4 OASGraph Library Open API
 Specification GraphQL Schema Express-graphql REST GraphQL
  • 8. INSTALL OASGRAPH DEPENDENCY npm install oasgraph —save cd loopback4-example-todo-list npm install express-graphql —save
  • 9. Modify src/application.ts options = Object.assign({}, { rest: { openApiSpec: { servers: [{url:'http://localhost:3000'}], } } }); Add the following code before the super(options); This will help OASGraph determine the URL for the resolver(s).
  • 10. At runtime the OpenApi Spec parameter OpenAPI Spec options = Object.assign({}, { rest: { openApiSpec: { servers: [{url:'http:// localhost:3000'}], } } }); GraphQL Schema "servers": [ { "url": "http://localhost:3000/" } ], Resolver URL
  • 11. Modify src/index.ts Import dependencies This will make the the express, express-graphql and oasgraph available. const OASGraph = require('oasgraph'); const express = require('express'); const graphqlHTTP = require('express-graphql');
  • 12. Modify src/index.ts Create the Schema Object Note that we are using the method getApiSpec from the LoopBack 4 rest server. This is the magic, the OASGraph.createGraphQlSchema is converting it to a GraphQL Schema automatically and accurately. const {schema} = await OASGraph.createGraphQlSchema( app.restServer.getApiSpec(), { strict: false, viewer: true, addSubOperations: true, sendOAuthTokeninQuery: false, }, ); Note: This code will be wrapped inside a try/catch. And starts after line console.log(`Try ${url}/ping`); LoopBack 4 OASGraph Library Open API
 Specification
  • 13. Modify src/index.ts Starts the GraphQL Server With the GraphQL schema generated already, it is just a matter of starting the GraphQL server in a specific port, in this case, we are using port 3001. const myExpress = express(); myExpress.use('/graphql', graphqlHTTP( { schema: schema, graphiql: true, } )); myExpress.listen(3001, () => { console.log('OASGraph ready at http://localhost:3001/graphql'); }); Note: This code will be wrapped inside a try/catch. OASGraph Library GraphQL Schema Express-graphql
  • 14. Full code src/index.ts The following code, should placed after rest server has been initiated. try { const {schema} = await OASGraph.createGraphQlSchema( app.restServer.getApiSpec(), { strict: false, viewer: true, addSubOperations: true, sendOAuthTokeninQuery: false, }, ); const myExpress = express(); myExpress.use('/graphql', graphqlHTTP({schema: schema, graphiql: true})); myExpress.listen(3001, () => { console.log('OASGraph ready at http://localhost:3001/graphql'); }); } catch (err) { console.log('Error: ', err.message); } return app;
 }
  • 15. Now run the application npm start > node . Server is running at http://[::1]:3000 OASGraph ready at http://localhost:3001/graphql End point for GraphQL Server
  • 16. Use GraphiQL tool Open in browser at http://localhost:3001/graphql
  • 18. Thank you ! Visit http://v4.loopback.io