SlideShare a Scribd company logo
GraphQL – the future
of APIs?
- OR -

GraphQL in a brief
Dmitry Stropalov, Sizmek Kraków 2017
What is GraphQL
• GraphQL is a (query) language
- declarative

- hierarchical 

- strongly typed
• GraphQL is a runtime

- execution layer

- technology agnostic
2
Yet another technology?
• Era of mobile devices

• Flexibility & Transparency

• Productivity & Costs
3
Some example
4
I have a data. What’s next?
5
1. Define a schema for data representation
GraphQL Schema:
type Campaign {
name: ID!
title: String
running: Boolean
ads: [Ad]
}
Elixir DSL:
object :campaign do
field :id, non_null(:id)
field :title, :string
field :running, :boolean
field :ads, list_of(:ad),
resolve: assoc(:ads)
end
I have a data. What’s next?
6
2. Define a schema of queries and mutations
GraphQL Schema:
type Query {
campaign(id: ID!): Campaign
}
Elixir DSL:
field :campaign, :campaign do
arg :id, non_null(:id)
resolve &CampaignResolver.find/2
end
I have a data. What’s next?
7
3. Implement resolvers for queries and mutations
Elixir:
def find(%{id: id}, _info) do
case Repo.get(Campaign, id) do
nil -> {:error, "Campaign #{id} not found"}
campaign -> {:ok, campaign}
end
end
I have a data. What’s next?
8
4. Make some queries
GraphQL query:
query {
campaign(id: 1) {
running
ads {
budget {
amount
}
}
}
}
GraphQL mutation:
mutation {
createCampaign(
title: "New campaign",
running: false, ads: [
{title: “LI 1"}
]) {
id
}
}
GraphQL Schema
9
• Scalar Types

• Lists & Enumeration Types

• Object Types

• Interfaces & Unions

• Arguments

• Input types
Scalar Types
10
• Int: A signed 32‐bit integer.

• Float: A signed double-precision floating-point value.

• String: A UTF‐8 character sequence.

• Boolean: true or false.

• ID: non human-readable String.

• Custom scalars via scalar keyword.
Lists & Enumeration Types
• Lists defined with [ and ] around type.

• Enum – special type of scalar with a restricted set of
possible values:



enum Episode {

FIRST

SECOND

THIRD

}
11
Object Types
• Object type – named set of fields with theirs types.

• Fields could be scalars or other object types, enums, lists.

• Fields could be marked as non-nullable:



type Ad {

title: String!

targetings: [Targeting!]!

}
12
Interfaces & Unions
• Interface – an abstract object type:

interface Player {

nickname: String!

}

type User implements Player {

nickname: String!

…

}

• Union – specifies a set of possible object types:

union SearchResult = Picture | Video | Document



search(text: "Kraków") {

… on Picture { size }

… on Video { length }

… on Document { format }

}
13
Arguments
• Every field of an object type can have zero or more
arguments:

type FuelTank {

volume(unit: VolumeUnit = LITRE): Float

}

• All arguments are named.

• Could be required or optional.
14
Input Types
• Input types – object types used for mutations.

• Input and output object types can’t be mixed.

• No arguments on input object fields.
15
GraphQL Queries
16
Fields, aliases, fragments and other things
Introspection & Docs
• Introspection is built-in via special __schema object.

• Any type introspection via __type object.

• Documentation is a part of schema definition:



@desc "Get campaign by ID."

field :campaign, :campaign do

arg :id, non_null(:id), description: "Specifies campaign ID.”

resolve &CampaignResolver.find/2

end
17
API Versioning
• GraphQL can’t have “v1”-style versioning.

• Evolution is the key.
18
One more “v1” thing
19
–Monty Python
“And now for something completely different …”
20
The Glory of REST
21
From the article “Richardson Maturity Model” by M.Fowler
GraphQL & REST
• GraphQL is a language, specification and tools while REST is an
architectural concept.

• GraphQL is completely independent of a transport protocol used.

• With GraphQL you can think in terms of a business logic objects
instead of resources.

• Different caching approaches.

• API payload optimisations.

• Field usage monitoring.
22
Adoption
• Facebook

• GitHub

• Twitter

• Airbnb

• The New York Times

• Wirtualna Polska

• Coursera

• Dailymotion
23
The End

More Related Content

PDF
Object oriented fundamentals_in_java
ODP
GraphQL with Sangria
PDF
TinkerPop 2020
DOCX
PPTX
Object Oriented Programming Languages
PDF
An Algebraic Data Model for Graphs and Hypergraphs (Category Theory meetup, N...
PDF
[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...
PDF
GraphQL as a REST API alternative
Object oriented fundamentals_in_java
GraphQL with Sangria
TinkerPop 2020
Object Oriented Programming Languages
An Algebraic Data Model for Graphs and Hypergraphs (Category Theory meetup, N...
[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...
GraphQL as a REST API alternative

Similar to GraphQL – the future of APIs? (20)

PDF
GraphQL with .NET Core Microservices.pdf
PDF
GraphQL - A love story
PDF
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
PDF
DEVOXX UK 2018 - GraphQL as an alternative approach to REST
PDF
Modern APIs with GraphQL
PPTX
PDF
Let's start GraphQL: structure, behavior, and architecture
PPTX
GraphQL - The new "Lingua Franca" for API-Development
PDF
PDF
GraphQL for Native Apps
PPTX
Introduction to GraphQL
PDF
PPTX
GraphQL @ Manc.JS (March 2018)
PDF
GraphQL the holy contract between client and server
PPTX
Introduction to GraphQL Presentation.pptx
PDF
Introduction to GraphQL for beginners
PDF
Graphql
PDF
Introduction to GraphQL
PDF
apidays LIVE Paris - GraphQL meshes by Jens Neuse
PDF
GraphQL over REST at Reactathon 2018
GraphQL with .NET Core Microservices.pdf
GraphQL - A love story
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
DEVOXX UK 2018 - GraphQL as an alternative approach to REST
Modern APIs with GraphQL
Let's start GraphQL: structure, behavior, and architecture
GraphQL - The new "Lingua Franca" for API-Development
GraphQL for Native Apps
Introduction to GraphQL
GraphQL @ Manc.JS (March 2018)
GraphQL the holy contract between client and server
Introduction to GraphQL Presentation.pptx
Introduction to GraphQL for beginners
Graphql
Introduction to GraphQL
apidays LIVE Paris - GraphQL meshes by Jens Neuse
GraphQL over REST at Reactathon 2018
Ad

Recently uploaded (20)

PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Understanding Forklifts - TECH EHS Solution
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
medical staffing services at VALiNTRY
PDF
Digital Strategies for Manufacturing Companies
PPTX
Essential Infomation Tech presentation.pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
ai tools demonstartion for schools and inter college
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Design an Analysis of Algorithms I-SECS-1021-03
Reimagine Home Health with the Power of Agentic AI​
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Understanding Forklifts - TECH EHS Solution
How Creative Agencies Leverage Project Management Software.pdf
PTS Company Brochure 2025 (1).pdf.......
Navsoft: AI-Powered Business Solutions & Custom Software Development
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
CHAPTER 2 - PM Management and IT Context
Design an Analysis of Algorithms II-SECS-1021-03
medical staffing services at VALiNTRY
Digital Strategies for Manufacturing Companies
Essential Infomation Tech presentation.pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Internet Downloader Manager (IDM) Crack 6.42 Build 41
How to Migrate SBCGlobal Email to Yahoo Easily
ai tools demonstartion for schools and inter college
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Design an Analysis of Algorithms I-SECS-1021-03
Ad

GraphQL – the future of APIs?

  • 1. GraphQL – the future of APIs? - OR - GraphQL in a brief Dmitry Stropalov, Sizmek Kraków 2017
  • 2. What is GraphQL • GraphQL is a (query) language - declarative - hierarchical - strongly typed • GraphQL is a runtime - execution layer - technology agnostic 2
  • 3. Yet another technology? • Era of mobile devices • Flexibility & Transparency • Productivity & Costs 3
  • 5. I have a data. What’s next? 5 1. Define a schema for data representation GraphQL Schema: type Campaign { name: ID! title: String running: Boolean ads: [Ad] } Elixir DSL: object :campaign do field :id, non_null(:id) field :title, :string field :running, :boolean field :ads, list_of(:ad), resolve: assoc(:ads) end
  • 6. I have a data. What’s next? 6 2. Define a schema of queries and mutations GraphQL Schema: type Query { campaign(id: ID!): Campaign } Elixir DSL: field :campaign, :campaign do arg :id, non_null(:id) resolve &CampaignResolver.find/2 end
  • 7. I have a data. What’s next? 7 3. Implement resolvers for queries and mutations Elixir: def find(%{id: id}, _info) do case Repo.get(Campaign, id) do nil -> {:error, "Campaign #{id} not found"} campaign -> {:ok, campaign} end end
  • 8. I have a data. What’s next? 8 4. Make some queries GraphQL query: query { campaign(id: 1) { running ads { budget { amount } } } } GraphQL mutation: mutation { createCampaign( title: "New campaign", running: false, ads: [ {title: “LI 1"} ]) { id } }
  • 9. GraphQL Schema 9 • Scalar Types • Lists & Enumeration Types • Object Types • Interfaces & Unions • Arguments • Input types
  • 10. Scalar Types 10 • Int: A signed 32‐bit integer. • Float: A signed double-precision floating-point value. • String: A UTF‐8 character sequence. • Boolean: true or false. • ID: non human-readable String. • Custom scalars via scalar keyword.
  • 11. Lists & Enumeration Types • Lists defined with [ and ] around type. • Enum – special type of scalar with a restricted set of possible values:
 
 enum Episode {
 FIRST
 SECOND
 THIRD
 } 11
  • 12. Object Types • Object type – named set of fields with theirs types. • Fields could be scalars or other object types, enums, lists. • Fields could be marked as non-nullable:
 
 type Ad {
 title: String!
 targetings: [Targeting!]!
 } 12
  • 13. Interfaces & Unions • Interface – an abstract object type:
 interface Player {
 nickname: String!
 }
 type User implements Player {
 nickname: String!
 …
 } • Union – specifies a set of possible object types:
 union SearchResult = Picture | Video | Document
 
 search(text: "Kraków") {
 … on Picture { size }
 … on Video { length }
 … on Document { format }
 } 13
  • 14. Arguments • Every field of an object type can have zero or more arguments:
 type FuelTank {
 volume(unit: VolumeUnit = LITRE): Float
 } • All arguments are named. • Could be required or optional. 14
  • 15. Input Types • Input types – object types used for mutations. • Input and output object types can’t be mixed. • No arguments on input object fields. 15
  • 16. GraphQL Queries 16 Fields, aliases, fragments and other things
  • 17. Introspection & Docs • Introspection is built-in via special __schema object. • Any type introspection via __type object. • Documentation is a part of schema definition:
 
 @desc "Get campaign by ID."
 field :campaign, :campaign do
 arg :id, non_null(:id), description: "Specifies campaign ID.”
 resolve &CampaignResolver.find/2
 end 17
  • 18. API Versioning • GraphQL can’t have “v1”-style versioning. • Evolution is the key. 18
  • 19. One more “v1” thing 19
  • 20. –Monty Python “And now for something completely different …” 20
  • 21. The Glory of REST 21 From the article “Richardson Maturity Model” by M.Fowler
  • 22. GraphQL & REST • GraphQL is a language, specification and tools while REST is an architectural concept. • GraphQL is completely independent of a transport protocol used. • With GraphQL you can think in terms of a business logic objects instead of resources. • Different caching approaches. • API payload optimisations. • Field usage monitoring. 22
  • 23. Adoption • Facebook • GitHub • Twitter • Airbnb • The New York Times • Wirtualna Polska • Coursera • Dailymotion 23