SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Ähnlich wie GraphQL – the future of APIs?

MongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScript
MongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScriptMongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScript
MongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScriptMongoDB
 
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...All Things Open
 
Tutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPAndrew Rota
 
How and Where in GLORP
How and Where in GLORPHow and Where in GLORP
How and Where in GLORPESUG
 
Building a GraphQL API in PHP
Building a GraphQL API in PHPBuilding a GraphQL API in PHP
Building a GraphQL API in PHPAndrew Rota
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptxarjun431527
 
Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...
Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...
Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...Databricks
 
OODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsOODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsShanmuganathan C
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programmingMohammed Romi
 
OpenAPI development with Python
OpenAPI development with PythonOpenAPI development with Python
OpenAPI development with PythonTakuro Wada
 
Enforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationEnforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationTim Burks
 
The advantage of developing with TypeScript
The advantage of developing with TypeScript The advantage of developing with TypeScript
The advantage of developing with TypeScript Corley S.r.l.
 

Ähnlich wie GraphQL – the future of APIs? (20)

GraphQl Introduction
GraphQl IntroductionGraphQl Introduction
GraphQl Introduction
 
Angular
AngularAngular
Angular
 
GraphQL + relay
GraphQL + relayGraphQL + relay
GraphQL + relay
 
HyperGraphQL
HyperGraphQLHyperGraphQL
HyperGraphQL
 
MongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScript
MongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScriptMongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScript
MongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScript
 
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
 
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
 
Graphql usage
Graphql usageGraphql usage
Graphql usage
 
How and Where in GLORP
How and Where in GLORPHow and Where in GLORP
How and Where in GLORP
 
GraphQL 101
GraphQL 101GraphQL 101
GraphQL 101
 
Revealing ALLSTOCKER
Revealing ALLSTOCKERRevealing ALLSTOCKER
Revealing ALLSTOCKER
 
Building a GraphQL API in PHP
Building a GraphQL API in PHPBuilding a GraphQL API in PHP
Building a GraphQL API in PHP
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptx
 
Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...
Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...
Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...
 
OODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsOODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objects
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programming
 
OpenAPI development with Python
OpenAPI development with PythonOpenAPI development with Python
OpenAPI development with Python
 
Enforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationEnforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code Generation
 
The advantage of developing with TypeScript
The advantage of developing with TypeScript The advantage of developing with TypeScript
The advantage of developing with TypeScript
 
AngularConf2015
AngularConf2015AngularConf2015
AngularConf2015
 

Kürzlich hochgeladen

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 

Kürzlich hochgeladen (20)

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 

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