SlideShare a Scribd company logo
1 of 54
Download to read offline
REST WEB SERVICE? NO,
GRAPHQL PLEASE!
DIMITRI GIELIS
DIMITRI GIELIS
ABOUT ME
▸ Founder & CEO of APEX R&D
▸ 20+ years of Oracle Experience 

(OCP & APEX Certified)
▸ Oracle ACE Director
▸ “APEX Developer of the year 2009” by Oracle Magazine
▸ “Oracle Developer Choice award (ORDS)” in 2015
▸ Author Expert Oracle APEX
▸ Presenter at Conferences
www.apexofficeprint.comwww.apexRnD.be
http://dgielis.blogspot.com @dgielis
WAYS TO QUERY THE DATABASE?
SQL
REST
GraphQL
SQL
STRUCTUREDQL
GRAPHQL
REST
CREATE API?
REST API
/hr/employees/:id
GET RESPONSE
REST API
CHARACTERISTICS
▸ Server controls the data you get
▸ May need multiple requests to obtain data
▸ Static versions of API
GRAPHQL
CREATE API?
GRAPHQL API
/hr
GET RESPONSE
Query
GRAPHQL
CHARACTERISTICS
▸ Server defines what is available, 

but Client controls the data it get
▸ Single request to get all
▸ Evolve API over time 

(even make fields deprecated)
▸ Auto documented
https://graphql.org
GRAPHQL
HISTORY
▸ Facebook's mobile apps have been powered by GraphQL
since 2012.
▸ A GraphQL spec was open sourced in 2015
▸ Many implementations in different languages
▸ Used by many big companies e.g.
DEMO (CONSUMING)
https://graphql.org/swapi-graphql/
https://www.graphqlhub.com
http://join-monster.herokuapp.com
MORE EXAMPLES
GRAPHQL APIS
▸ https://github.com/APIs-guru/graphql-apis
▸ https://help.shopify.com/en/api/graphql-admin-api/
graphiql-explorer
▸ https://developer.github.com/v4/
▸ https://www.yelp.com/developers/graphql/guides/intro
GETTING
STARTED
GRAPHQL AND THE
ORACLE DATABASE
GRAPHQL AND THE ORACLE DATABASE
BUILDING BLOCKS
▸ Oracle Database
▸ node.js
▸ oracledb
▸ graphql
▸ apollo-server
MY DEVELOPMENT ENVIRONMENT
▸ Visual Studio Code
▸ Sqlcl
▸ Git
▸ node.js & nvm & npm
▸ Instant Oracle client / Oracle Database
INSTALLATION NODE.JS
https://nodejs.org/
GETTING STARTED
CREATE A FIRST NODE PROJECT
▸ npm init
▸ npm install apollo-server graphql oracledb
GETTING STARTED
CREATE A FIRST NODE PROJECT
▸ npm init
▸ npm install apollo-server graphql oracledb
GETTING STARTED
CREATE A FIRST NODE PROJECT
▸ npm init
▸ npm install apollo-server graphql oracledb
GETTING STARTED
CREATE A FIRST NODE PROJECT
▸ npm init
▸ npm install apollo-server graphql oracledb
ABOUT APOLLO
Apollo Server is the best way to quickly build a production-ready, self-documenting API for
GraphQL clients, using data from any source - https://www.apollographql.com/docs/apollo-server/
CREATE AN APOLLO SERVER
const { ApolloServer, gql } = require('apollo-server');
// This is a (sample) collection of books
const books = [{title: 'Book1'},{title: 'Book2'}];
// Type definitions define the "shape" of your data
const typeDefs = gql`
type Book {title: String}
type Query {books: [Book]}
`;
// Resolvers define the technique for fetching the types
const resolvers = { Query: {books: () => books } };
// The Apollo Server can be started by passing
// type definitions and the resolvers
const server = new ApolloServer({ typeDefs, resolvers });
// This `listen` method launches a web-server
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
https://www.apollographql.com/docs/apollo-server/getting-started/
CREATE AN APOLLO SERVER
const { ApolloServer, gql } = require('apollo-server');
// This is a (sample) collection of books
const books = [{title: 'Book1'},{title: 'Book2'}];
// Type definitions define the "shape" of your data
const typeDefs = gql`
type Book {title: String}
type Query {books: [Book]}
`;
// Resolvers define the technique for fetching the types
const resolvers = { Query: {books: () => books } };
// The Apollo Server can be started by passing
// type definitions and the resolvers
const server = new ApolloServer({ typeDefs, resolvers });
// This `listen` method launches a web-server
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
https://www.apollographql.com/docs/apollo-server/getting-started/
CREATE AN APOLLO SERVER
const { ApolloServer, gql } = require('apollo-server');
// This is a (sample) collection of books
const books = [{title: 'Book1'},{title: 'Book2'}];
// Type definitions define the "shape" of your data
const typeDefs = gql`
type Book {title: String}
type Query {books: [Book]}
`;
// Resolvers define the technique for fetching the types
const resolvers = { Query: {books: () => books } };
// The Apollo Server can be started by passing
// type definitions and the resolvers
const server = new ApolloServer({ typeDefs, resolvers });
// This `listen` method launches a web-server
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
https://www.apollographql.com/docs/apollo-server/getting-started/
CREATE AN APOLLO SERVER
const { ApolloServer, gql } = require('apollo-server');
// This is a (sample) collection of books
const books = [{title: 'Book1'},{title: 'Book2'}];
// Type definitions define the "shape" of your data
const typeDefs = gql`
type Book {title: String}
type Query {books: [Book]}
`;
// Resolvers define the technique for fetching the types
const resolvers = { Query: {books: () => books } };
// The Apollo Server can be started by passing
// type definitions and the resolvers
const server = new ApolloServer({ typeDefs, resolvers });
// This `listen` method launches a web-server
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
https://www.apollographql.com/docs/apollo-server/getting-started/
CREATE AN APOLLO SERVER
const { ApolloServer, gql } = require('apollo-server');
// This is a (sample) collection of books
const books = [{title: 'Book1'},{title: 'Book2'}];
// Type definitions define the "shape" of your data
const typeDefs = gql`
type Book {title: String}
type Query {books: [Book]}
`;
// Resolvers define the technique for fetching the types
const resolvers = { Query: {books: () => books } };
// The Apollo Server can be started by passing
// type definitions and the resolvers
const server = new ApolloServer({ typeDefs, resolvers });
// This `listen` method launches a web-server
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
https://www.apollographql.com/docs/apollo-server/getting-started/
CREATE AN APOLLO SERVER
const { ApolloServer, gql } = require('apollo-server');
// This is a (sample) collection of books
const books = [{title: 'Book1'},{title: 'Book2'}];
// Type definitions define the "shape" of your data
const typeDefs = gql`
type Book {title: String}
type Query {books: [Book]}
`;
// Resolvers define the technique for fetching the types
const resolvers = { Query: {books: () => books } };
// The Apollo Server can be started by passing
// type definitions and the resolvers
const server = new ApolloServer({ typeDefs, resolvers });
// This `listen` method launches a web-server
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
https://www.apollographql.com/docs/apollo-server/getting-started/
CREATE AN APOLLO SERVER
const { ApolloServer, gql } = require('apollo-server');
// This is a (sample) collection of books
const books = [{title: 'Book1'},{title: 'Book2'}];
// Type definitions define the "shape" of your data
const typeDefs = gql`
type Book {title: String}
type Query {books: [Book]}
`;
// Resolvers define the technique for fetching the types
const resolvers = { Query: {books: () => books } };
// The Apollo Server can be started by passing
// type definitions and the resolvers
const server = new ApolloServer({ typeDefs, resolvers });
// This `listen` method launches a web-server
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
https://www.apollographql.com/docs/apollo-server/getting-started/
TEST IN BROWSER: HTTP://LOCALHOST:4000
HOOKING UP ORACLE DB WITH NODE-ORACLEDB
QUERY ORACLE DB
var oracledb = require('oracledb');
async function run() {
let connection;
try {
connection = await oracledb.getConnection( {
user : "hr",
password : "hr",
connectString : "localhost/XEPDB1"
});
let result = await connection.execute(
`SELECT manager_id, department_id, department_name
FROM departments
WHERE manager_id = :id`,
[103], // bind value for :id
);
console.log(result.rows);
} catch (err) {
console.error(err);
} finally {
if (connection) {
try {
await connection.close();
} catch (err) {
console.error(err);
}
}
}
}
run();
https://oracle.github.io/node-oracledb/doc/api.html#getstarted
QUERY ORACLE DB
var oracledb = require('oracledb');
async function run() {
let connection;
try {
connection = await oracledb.getConnection( {
user : "hr",
password : "hr",
connectString : "localhost/XEPDB1"
});
let result = await connection.execute(
`SELECT manager_id, department_id, department_name
FROM departments
WHERE manager_id = :id`,
[103], // bind value for :id
);
console.log(result.rows);
} catch (err) {
console.error(err);
} finally {
if (connection) {
try {
await connection.close();
} catch (err) {
console.error(err);
}
}
}
}
run();
https://oracle.github.io/node-oracledb/doc/api.html#getstarted
QUERY ORACLE DB
var oracledb = require('oracledb');
async function run() {
let connection;
try {
connection = await oracledb.getConnection( {
user : "hr",
password : "hr",
connectString : "localhost/XEPDB1"
});
let result = await connection.execute(
`SELECT manager_id, department_id, department_name
FROM departments
WHERE manager_id = :id`,
[103], // bind value for :id
);
console.log(result.rows);
} catch (err) {
console.error(err);
} finally {
if (connection) {
try {
await connection.close();
} catch (err) {
console.error(err);
}
}
}
}
run();
https://oracle.github.io/node-oracledb/doc/api.html#getstarted
QUERY ORACLE DB
var oracledb = require('oracledb');
async function run() {
let connection;
try {
connection = await oracledb.getConnection( {
user : "hr",
password : "hr",
connectString : "localhost/XEPDB1"
});
let result = await connection.execute(
`SELECT manager_id, department_id, department_name
FROM departments
WHERE manager_id = :id`,
[103], // bind value for :id
);
console.log(result.rows);
} catch (err) {
console.error(err);
} finally {
if (connection) {
try {
await connection.close();
} catch (err) {
console.error(err);
}
}
}
}
run();
https://oracle.github.io/node-oracledb/doc/api.html#getstarted
GETTING STARTED
COMBINING APOLLO AND ORACLE
▸ Map SQL to Types
▸ TIP: 

sqlcl to output SQL statement to JSON
▸ convert JSON to GraphQL Types automatically

https://walmartlabs.github.io/json-to-simple-graphql-schema/
DEMO (PROVIDING)
source: https://www.apexofficeprint.com/graphql
MORE ADVANCED SQL & JOINS
JOIN MONSTER
▸ A GraphQL to SQL query execution layer for query
planning and batch data fetching.
https://github.com/acarl005/join-monster
DEMO (PROVIDING)
source: Dan McGhan presentation: emp/dept example
DETAILS OF GRAPHQL
GRAPHQL CONCEPTS
▸ Schema
▸ Object type (character)
▸ Field
▸ Arguments
▸ Scalar type
▸ Interface
DETAILS OF GRAPHQL
HOW TO QUERY A GRAPHQL SERVER
▸ Queries
▸ Fields, Aliases, Fragments
▸ Arguments
▸ Variables
▸ Directives
▸ Operation name
▸ Mutations
▸ Subscriptions
NEXT
INTERESTING RESOURCES & PROJECTS
▸ https://graphql.org/learn/best-practices/
▸ https://blogs.oracle.com/opal/demo:-graphql-with-node-oracledb
▸ https://github.com/sblack4/oracledb-graphql-demo
▸ https://www.prisma.io (no Oracle support yet)
▸ https://github.com/rexxars/sql-to-graphql (unmaintained)

More Related Content

Similar to REST Web Service? No, GraphQL please!

How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js frameworkBen Lin
 
Intro to fog and openstack jp
Intro to fog and openstack jpIntro to fog and openstack jp
Intro to fog and openstack jpSatoshi Konno
 
How to execute an oracle stored procedure with nested table as a parameter fr...
How to execute an oracle stored procedure with nested table as a parameter fr...How to execute an oracle stored procedure with nested table as a parameter fr...
How to execute an oracle stored procedure with nested table as a parameter fr...Priyobroto Ghosh (Mule ESB Certified)
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jerseyb_kathir
 
Managing GraphQL servers with AWS Fargate & Prisma Cloud
Managing GraphQL servers  with AWS Fargate & Prisma CloudManaging GraphQL servers  with AWS Fargate & Prisma Cloud
Managing GraphQL servers with AWS Fargate & Prisma CloudNikolas Burk
 
GraphQL & Prisma from Scratch
GraphQL & Prisma from ScratchGraphQL & Prisma from Scratch
GraphQL & Prisma from ScratchNikolas Burk
 
Serverless Ballerina
Serverless BallerinaServerless Ballerina
Serverless BallerinaBallerina
 
Scala45 spray test
Scala45 spray testScala45 spray test
Scala45 spray testkopiczko
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineGoogle Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineRoman Kirillov
 
Flask & Flask-restx
Flask & Flask-restxFlask & Flask-restx
Flask & Flask-restxammaraslam18
 
Microservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-dockerMicroservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-dockerKidong Lee
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CDavid Wheeler
 
Elasticsearch And Ruby [RuPy2012]
Elasticsearch And Ruby [RuPy2012]Elasticsearch And Ruby [RuPy2012]
Elasticsearch And Ruby [RuPy2012]Karel Minarik
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bitsChris Saylor
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyLaunchAny
 

Similar to REST Web Service? No, GraphQL please! (20)

How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
Intro to fog and openstack jp
Intro to fog and openstack jpIntro to fog and openstack jp
Intro to fog and openstack jp
 
Backbone
BackboneBackbone
Backbone
 
How to execute an oracle stored procedure with nested table as a parameter fr...
How to execute an oracle stored procedure with nested table as a parameter fr...How to execute an oracle stored procedure with nested table as a parameter fr...
How to execute an oracle stored procedure with nested table as a parameter fr...
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
 
Managing GraphQL servers with AWS Fargate & Prisma Cloud
Managing GraphQL servers  with AWS Fargate & Prisma CloudManaging GraphQL servers  with AWS Fargate & Prisma Cloud
Managing GraphQL servers with AWS Fargate & Prisma Cloud
 
Pyrax talk
Pyrax talkPyrax talk
Pyrax talk
 
GraphQL & Prisma from Scratch
GraphQL & Prisma from ScratchGraphQL & Prisma from Scratch
GraphQL & Prisma from Scratch
 
Serverless Ballerina
Serverless BallerinaServerless Ballerina
Serverless Ballerina
 
Scala45 spray test
Scala45 spray testScala45 spray test
Scala45 spray test
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineGoogle Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
 
Flask & Flask-restx
Flask & Flask-restxFlask & Flask-restx
Flask & Flask-restx
 
Corba
CorbaCorba
Corba
 
Microservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-dockerMicroservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-docker
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning C
 
Rack
RackRack
Rack
 
Openshift31-tech.ppt
Openshift31-tech.pptOpenshift31-tech.ppt
Openshift31-tech.ppt
 
Elasticsearch And Ruby [RuPy2012]
Elasticsearch And Ruby [RuPy2012]Elasticsearch And Ruby [RuPy2012]
Elasticsearch And Ruby [RuPy2012]
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 

More from Dimitri Gielis

Bring the light in your Always FREE Oracle Cloud
Bring the light in your Always FREE Oracle CloudBring the light in your Always FREE Oracle Cloud
Bring the light in your Always FREE Oracle CloudDimitri Gielis
 
APEX Office Print (AOP)
APEX Office Print (AOP)APEX Office Print (AOP)
APEX Office Print (AOP)Dimitri Gielis
 
Can You Do That with APEX? Building Not So Straightforward Pages
Can You Do That with APEX? Building Not So Straightforward PagesCan You Do That with APEX? Building Not So Straightforward Pages
Can You Do That with APEX? Building Not So Straightforward PagesDimitri Gielis
 
Bringing Virtual Reality (VR) and Augmented Reality (AR) to APEX
Bringing Virtual Reality (VR) and Augmented Reality (AR) to APEXBringing Virtual Reality (VR) and Augmented Reality (AR) to APEX
Bringing Virtual Reality (VR) and Augmented Reality (AR) to APEXDimitri Gielis
 
Reporting with Oracle Application Express (APEX)
Reporting with Oracle Application Express (APEX)Reporting with Oracle Application Express (APEX)
Reporting with Oracle Application Express (APEX)Dimitri Gielis
 
Moving your APEX app to the Oracle Exadata Express Cloud
Moving your APEX app to the Oracle Exadata Express CloudMoving your APEX app to the Oracle Exadata Express Cloud
Moving your APEX app to the Oracle Exadata Express CloudDimitri Gielis
 
Oracle APEX for Beginners
Oracle APEX for BeginnersOracle APEX for Beginners
Oracle APEX for BeginnersDimitri Gielis
 
JavaScript straight from the Oracle Database
JavaScript straight from the Oracle DatabaseJavaScript straight from the Oracle Database
JavaScript straight from the Oracle DatabaseDimitri Gielis
 
Service Workers and APEX
Service Workers and APEXService Workers and APEX
Service Workers and APEXDimitri Gielis
 
Real Application Security (RAS) and Oracle Application Express (APEX)
Real Application Security (RAS) and Oracle Application Express (APEX)Real Application Security (RAS) and Oracle Application Express (APEX)
Real Application Security (RAS) and Oracle Application Express (APEX)Dimitri Gielis
 
Moving to the APEX Listener
Moving to the APEX ListenerMoving to the APEX Listener
Moving to the APEX ListenerDimitri Gielis
 
APEX 5 Demo and Best Practices
APEX 5 Demo and Best PracticesAPEX 5 Demo and Best Practices
APEX 5 Demo and Best PracticesDimitri Gielis
 
A Primer on Web Components in APEX
A Primer on Web Components in APEXA Primer on Web Components in APEX
A Primer on Web Components in APEXDimitri Gielis
 
How to make APEX print through Node.js
How to make APEX print through Node.jsHow to make APEX print through Node.js
How to make APEX print through Node.jsDimitri Gielis
 
Oracle Application Express (APEX) and Microsoft Sharepoint integration
Oracle Application Express (APEX) and Microsoft Sharepoint integrationOracle Application Express (APEX) and Microsoft Sharepoint integration
Oracle Application Express (APEX) and Microsoft Sharepoint integrationDimitri Gielis
 

More from Dimitri Gielis (18)

Bring the light in your Always FREE Oracle Cloud
Bring the light in your Always FREE Oracle CloudBring the light in your Always FREE Oracle Cloud
Bring the light in your Always FREE Oracle Cloud
 
APEX Office Print (AOP)
APEX Office Print (AOP)APEX Office Print (AOP)
APEX Office Print (AOP)
 
Can You Do That with APEX? Building Not So Straightforward Pages
Can You Do That with APEX? Building Not So Straightforward PagesCan You Do That with APEX? Building Not So Straightforward Pages
Can You Do That with APEX? Building Not So Straightforward Pages
 
Bringing Virtual Reality (VR) and Augmented Reality (AR) to APEX
Bringing Virtual Reality (VR) and Augmented Reality (AR) to APEXBringing Virtual Reality (VR) and Augmented Reality (AR) to APEX
Bringing Virtual Reality (VR) and Augmented Reality (AR) to APEX
 
Reporting with Oracle Application Express (APEX)
Reporting with Oracle Application Express (APEX)Reporting with Oracle Application Express (APEX)
Reporting with Oracle Application Express (APEX)
 
Moving your APEX app to the Oracle Exadata Express Cloud
Moving your APEX app to the Oracle Exadata Express CloudMoving your APEX app to the Oracle Exadata Express Cloud
Moving your APEX app to the Oracle Exadata Express Cloud
 
Oracle APEX for Beginners
Oracle APEX for BeginnersOracle APEX for Beginners
Oracle APEX for Beginners
 
JavaScript straight from the Oracle Database
JavaScript straight from the Oracle DatabaseJavaScript straight from the Oracle Database
JavaScript straight from the Oracle Database
 
Service Workers and APEX
Service Workers and APEXService Workers and APEX
Service Workers and APEX
 
APEX Office Print
APEX Office PrintAPEX Office Print
APEX Office Print
 
Real Application Security (RAS) and Oracle Application Express (APEX)
Real Application Security (RAS) and Oracle Application Express (APEX)Real Application Security (RAS) and Oracle Application Express (APEX)
Real Application Security (RAS) and Oracle Application Express (APEX)
 
Moving to the APEX Listener
Moving to the APEX ListenerMoving to the APEX Listener
Moving to the APEX Listener
 
APEX Wearables
APEX WearablesAPEX Wearables
APEX Wearables
 
APEX Security 101
APEX Security 101APEX Security 101
APEX Security 101
 
APEX 5 Demo and Best Practices
APEX 5 Demo and Best PracticesAPEX 5 Demo and Best Practices
APEX 5 Demo and Best Practices
 
A Primer on Web Components in APEX
A Primer on Web Components in APEXA Primer on Web Components in APEX
A Primer on Web Components in APEX
 
How to make APEX print through Node.js
How to make APEX print through Node.jsHow to make APEX print through Node.js
How to make APEX print through Node.js
 
Oracle Application Express (APEX) and Microsoft Sharepoint integration
Oracle Application Express (APEX) and Microsoft Sharepoint integrationOracle Application Express (APEX) and Microsoft Sharepoint integration
Oracle Application Express (APEX) and Microsoft Sharepoint integration
 

Recently uploaded

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Recently uploaded (20)

E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

REST Web Service? No, GraphQL please!

  • 1. REST WEB SERVICE? NO, GRAPHQL PLEASE! DIMITRI GIELIS
  • 2. DIMITRI GIELIS ABOUT ME ▸ Founder & CEO of APEX R&D ▸ 20+ years of Oracle Experience 
 (OCP & APEX Certified) ▸ Oracle ACE Director ▸ “APEX Developer of the year 2009” by Oracle Magazine ▸ “Oracle Developer Choice award (ORDS)” in 2015 ▸ Author Expert Oracle APEX ▸ Presenter at Conferences
  • 5.
  • 6. WAYS TO QUERY THE DATABASE? SQL REST GraphQL
  • 7. SQL
  • 10.
  • 13. REST API CHARACTERISTICS ▸ Server controls the data you get ▸ May need multiple requests to obtain data ▸ Static versions of API
  • 16. GRAPHQL CHARACTERISTICS ▸ Server defines what is available, 
 but Client controls the data it get ▸ Single request to get all ▸ Evolve API over time 
 (even make fields deprecated) ▸ Auto documented
  • 18. GRAPHQL HISTORY ▸ Facebook's mobile apps have been powered by GraphQL since 2012. ▸ A GraphQL spec was open sourced in 2015 ▸ Many implementations in different languages ▸ Used by many big companies e.g.
  • 23. MORE EXAMPLES GRAPHQL APIS ▸ https://github.com/APIs-guru/graphql-apis ▸ https://help.shopify.com/en/api/graphql-admin-api/ graphiql-explorer ▸ https://developer.github.com/v4/ ▸ https://www.yelp.com/developers/graphql/guides/intro
  • 25. GRAPHQL AND THE ORACLE DATABASE BUILDING BLOCKS ▸ Oracle Database ▸ node.js ▸ oracledb ▸ graphql ▸ apollo-server
  • 26. MY DEVELOPMENT ENVIRONMENT ▸ Visual Studio Code ▸ Sqlcl ▸ Git ▸ node.js & nvm & npm ▸ Instant Oracle client / Oracle Database
  • 28. GETTING STARTED CREATE A FIRST NODE PROJECT ▸ npm init ▸ npm install apollo-server graphql oracledb
  • 29. GETTING STARTED CREATE A FIRST NODE PROJECT ▸ npm init ▸ npm install apollo-server graphql oracledb
  • 30. GETTING STARTED CREATE A FIRST NODE PROJECT ▸ npm init ▸ npm install apollo-server graphql oracledb
  • 31. GETTING STARTED CREATE A FIRST NODE PROJECT ▸ npm init ▸ npm install apollo-server graphql oracledb
  • 32. ABOUT APOLLO Apollo Server is the best way to quickly build a production-ready, self-documenting API for GraphQL clients, using data from any source - https://www.apollographql.com/docs/apollo-server/
  • 33. CREATE AN APOLLO SERVER const { ApolloServer, gql } = require('apollo-server'); // This is a (sample) collection of books const books = [{title: 'Book1'},{title: 'Book2'}]; // Type definitions define the "shape" of your data const typeDefs = gql` type Book {title: String} type Query {books: [Book]} `; // Resolvers define the technique for fetching the types const resolvers = { Query: {books: () => books } }; // The Apollo Server can be started by passing // type definitions and the resolvers const server = new ApolloServer({ typeDefs, resolvers }); // This `listen` method launches a web-server server.listen().then(({ url }) => { console.log(`🚀 Server ready at ${url}`); }); https://www.apollographql.com/docs/apollo-server/getting-started/
  • 34. CREATE AN APOLLO SERVER const { ApolloServer, gql } = require('apollo-server'); // This is a (sample) collection of books const books = [{title: 'Book1'},{title: 'Book2'}]; // Type definitions define the "shape" of your data const typeDefs = gql` type Book {title: String} type Query {books: [Book]} `; // Resolvers define the technique for fetching the types const resolvers = { Query: {books: () => books } }; // The Apollo Server can be started by passing // type definitions and the resolvers const server = new ApolloServer({ typeDefs, resolvers }); // This `listen` method launches a web-server server.listen().then(({ url }) => { console.log(`🚀 Server ready at ${url}`); }); https://www.apollographql.com/docs/apollo-server/getting-started/
  • 35. CREATE AN APOLLO SERVER const { ApolloServer, gql } = require('apollo-server'); // This is a (sample) collection of books const books = [{title: 'Book1'},{title: 'Book2'}]; // Type definitions define the "shape" of your data const typeDefs = gql` type Book {title: String} type Query {books: [Book]} `; // Resolvers define the technique for fetching the types const resolvers = { Query: {books: () => books } }; // The Apollo Server can be started by passing // type definitions and the resolvers const server = new ApolloServer({ typeDefs, resolvers }); // This `listen` method launches a web-server server.listen().then(({ url }) => { console.log(`🚀 Server ready at ${url}`); }); https://www.apollographql.com/docs/apollo-server/getting-started/
  • 36. CREATE AN APOLLO SERVER const { ApolloServer, gql } = require('apollo-server'); // This is a (sample) collection of books const books = [{title: 'Book1'},{title: 'Book2'}]; // Type definitions define the "shape" of your data const typeDefs = gql` type Book {title: String} type Query {books: [Book]} `; // Resolvers define the technique for fetching the types const resolvers = { Query: {books: () => books } }; // The Apollo Server can be started by passing // type definitions and the resolvers const server = new ApolloServer({ typeDefs, resolvers }); // This `listen` method launches a web-server server.listen().then(({ url }) => { console.log(`🚀 Server ready at ${url}`); }); https://www.apollographql.com/docs/apollo-server/getting-started/
  • 37. CREATE AN APOLLO SERVER const { ApolloServer, gql } = require('apollo-server'); // This is a (sample) collection of books const books = [{title: 'Book1'},{title: 'Book2'}]; // Type definitions define the "shape" of your data const typeDefs = gql` type Book {title: String} type Query {books: [Book]} `; // Resolvers define the technique for fetching the types const resolvers = { Query: {books: () => books } }; // The Apollo Server can be started by passing // type definitions and the resolvers const server = new ApolloServer({ typeDefs, resolvers }); // This `listen` method launches a web-server server.listen().then(({ url }) => { console.log(`🚀 Server ready at ${url}`); }); https://www.apollographql.com/docs/apollo-server/getting-started/
  • 38. CREATE AN APOLLO SERVER const { ApolloServer, gql } = require('apollo-server'); // This is a (sample) collection of books const books = [{title: 'Book1'},{title: 'Book2'}]; // Type definitions define the "shape" of your data const typeDefs = gql` type Book {title: String} type Query {books: [Book]} `; // Resolvers define the technique for fetching the types const resolvers = { Query: {books: () => books } }; // The Apollo Server can be started by passing // type definitions and the resolvers const server = new ApolloServer({ typeDefs, resolvers }); // This `listen` method launches a web-server server.listen().then(({ url }) => { console.log(`🚀 Server ready at ${url}`); }); https://www.apollographql.com/docs/apollo-server/getting-started/
  • 39. CREATE AN APOLLO SERVER const { ApolloServer, gql } = require('apollo-server'); // This is a (sample) collection of books const books = [{title: 'Book1'},{title: 'Book2'}]; // Type definitions define the "shape" of your data const typeDefs = gql` type Book {title: String} type Query {books: [Book]} `; // Resolvers define the technique for fetching the types const resolvers = { Query: {books: () => books } }; // The Apollo Server can be started by passing // type definitions and the resolvers const server = new ApolloServer({ typeDefs, resolvers }); // This `listen` method launches a web-server server.listen().then(({ url }) => { console.log(`🚀 Server ready at ${url}`); }); https://www.apollographql.com/docs/apollo-server/getting-started/
  • 40. TEST IN BROWSER: HTTP://LOCALHOST:4000
  • 41. HOOKING UP ORACLE DB WITH NODE-ORACLEDB
  • 42. QUERY ORACLE DB var oracledb = require('oracledb'); async function run() { let connection; try { connection = await oracledb.getConnection( { user : "hr", password : "hr", connectString : "localhost/XEPDB1" }); let result = await connection.execute( `SELECT manager_id, department_id, department_name FROM departments WHERE manager_id = :id`, [103], // bind value for :id ); console.log(result.rows); } catch (err) { console.error(err); } finally { if (connection) { try { await connection.close(); } catch (err) { console.error(err); } } } } run(); https://oracle.github.io/node-oracledb/doc/api.html#getstarted
  • 43. QUERY ORACLE DB var oracledb = require('oracledb'); async function run() { let connection; try { connection = await oracledb.getConnection( { user : "hr", password : "hr", connectString : "localhost/XEPDB1" }); let result = await connection.execute( `SELECT manager_id, department_id, department_name FROM departments WHERE manager_id = :id`, [103], // bind value for :id ); console.log(result.rows); } catch (err) { console.error(err); } finally { if (connection) { try { await connection.close(); } catch (err) { console.error(err); } } } } run(); https://oracle.github.io/node-oracledb/doc/api.html#getstarted
  • 44. QUERY ORACLE DB var oracledb = require('oracledb'); async function run() { let connection; try { connection = await oracledb.getConnection( { user : "hr", password : "hr", connectString : "localhost/XEPDB1" }); let result = await connection.execute( `SELECT manager_id, department_id, department_name FROM departments WHERE manager_id = :id`, [103], // bind value for :id ); console.log(result.rows); } catch (err) { console.error(err); } finally { if (connection) { try { await connection.close(); } catch (err) { console.error(err); } } } } run(); https://oracle.github.io/node-oracledb/doc/api.html#getstarted
  • 45. QUERY ORACLE DB var oracledb = require('oracledb'); async function run() { let connection; try { connection = await oracledb.getConnection( { user : "hr", password : "hr", connectString : "localhost/XEPDB1" }); let result = await connection.execute( `SELECT manager_id, department_id, department_name FROM departments WHERE manager_id = :id`, [103], // bind value for :id ); console.log(result.rows); } catch (err) { console.error(err); } finally { if (connection) { try { await connection.close(); } catch (err) { console.error(err); } } } } run(); https://oracle.github.io/node-oracledb/doc/api.html#getstarted
  • 46. GETTING STARTED COMBINING APOLLO AND ORACLE ▸ Map SQL to Types ▸ TIP: 
 sqlcl to output SQL statement to JSON ▸ convert JSON to GraphQL Types automatically
 https://walmartlabs.github.io/json-to-simple-graphql-schema/
  • 47.
  • 49. MORE ADVANCED SQL & JOINS JOIN MONSTER ▸ A GraphQL to SQL query execution layer for query planning and batch data fetching. https://github.com/acarl005/join-monster
  • 50. DEMO (PROVIDING) source: Dan McGhan presentation: emp/dept example
  • 51.
  • 52. DETAILS OF GRAPHQL GRAPHQL CONCEPTS ▸ Schema ▸ Object type (character) ▸ Field ▸ Arguments ▸ Scalar type ▸ Interface
  • 53. DETAILS OF GRAPHQL HOW TO QUERY A GRAPHQL SERVER ▸ Queries ▸ Fields, Aliases, Fragments ▸ Arguments ▸ Variables ▸ Directives ▸ Operation name ▸ Mutations ▸ Subscriptions
  • 54. NEXT INTERESTING RESOURCES & PROJECTS ▸ https://graphql.org/learn/best-practices/ ▸ https://blogs.oracle.com/opal/demo:-graphql-with-node-oracledb ▸ https://github.com/sblack4/oracledb-graphql-demo ▸ https://www.prisma.io (no Oracle support yet) ▸ https://github.com/rexxars/sql-to-graphql (unmaintained)