SlideShare a Scribd company logo
Symfony + GraphQL
Alex Demchenko
alex@lazy-ants.com
Alex Demchenko
Lazy Ants founder & CEO
GraphQL
query language and execution engine
https://graphql.org/
Created by Facebook at 2012
Become an open standard at 2015
Latest update at June 2018
http://facebook.github.io/graphql/June2018/
Improvements over REST
One endpoint
Query
Get User posts REST style
http://lznz.eu/api/user/444/posts
Get User posts REST style
http://lznz.eu/api/user/444/posts
- What information does that give us?
Get User posts REST style
http://lznz.eu/api/user/444/posts
- What information does that give us?
- What data will come from that request?
Get User posts REST style
You said Swager for API doc?
Get User posts REST style
fck tons of annotations
to explain each endpoints
Get User posts REST style
You are waste your time,
instead of bring
Business Value
Get User posts REST style
http://lznz.eu/api/user/444/posts
http://lznz.eu/api/post/4/comments?last=5
http://lznz.eu/api/post/5/comments?last=5
Ok Ok create a custom endpoint
http://lznz.eu/api/user/444/posts
?with=comments&lastComments=5
GraphQL style
query userPosts {
posts(userId: 45) {
id
title
text
createdAt
}
}
GraphQL style
query {
articles(first: 3, sortBy: “date”){
id
title
body
published
category{
id
name
}
}
}
Desktop or Mobile
query userPosts {
posts(userId: 45) {
id
title
text
createdAt
}
}
query userPosts {
posts(userId: 45) {
id
title
}
}
Symfony + GraphQL
Symfony + GraphQL
Symfony + GraphQL
Symfony + GraphQL
Symfony + GraphQL
Symfony + GraphQL
Symfony + GraphQL
Symfony + GraphQL
ERRORS?
Cursor Connections
#R2D2 ->"YXJyYXljb25uZWN0aW9uOjI="
query codeIDget3AfterCursor {
allPeople(
first: 3,
after: "YXJyYXljb25uZWN0aW9uOjI="
) {
edges {
node {
name
}
cursor
}
}
}
https://graphql.org/swapi-graphql/?query=query%20pumparam%20%7B%0A%09all
Cursor Connections
{
"data": {
"allPeople": {
"edges": [
...
{
"node": {
"name": "Owen Lars"
},
"cursor": "YXJyYXljb25uZWN0aW9uOjU="
}
]
}
}
}
https://graphql.org/swapi-graphql/?query=query%20pumparam%20%7B%0A%09all
GraphQL prevents HTTP overfetching
Mutations
Mutations
mutation {
createReview(input: {
episodeID: 4,
content: "hope is a good thing",
rating: 5
}) {
id
}
}
With GraphQL the server code
is clean and well-organized
Symfony implementation
https://github.com/
youshido-php/GraphQLBundle
275 Stars
https://github.com/youshido-php/GraphQL - 660 stars
https://github.com/
overblog/GraphQLBundle
338 Stars
https://github.com/webonyx/graphql-php - 2384 stars
Interface
# Resources/graphql/character.types.yml
Character:
type: interface
config:
fields:
id:
type: "String"
name:
type: "String"
friends:
type: "[Character]"
description: "The friends of the character."
appearsIn:
type: "[Film]"
description: "Which movies they appear in."
Object
# Resources/graphql/human.types.yml
Human:
type: object
config:
fields:
id:
type: "String"
name:
type: "String"
homeWorld:
type: World
interfaces: [Character]
isTypeOf: true
Entry point -> Query
# Resources/graphql/query.types.yml
Query:
type: object
config:
description: "All Star Wars queries"
fields:
allHumans:
type: "[Human]"
resolve: "@=resolver('allHumans', [args])" # Symfony Expression Language
human:
type: "Human"
resolve: "@=resolver('human', [args['id'])" # Symfony Expression Language
args:
id:
description: "Human's UUID"
type: "String!"
Mutation Entry Point
# Resources/graphql/Mutation.types.yml
Mutation:
type: object
config:
description: "All Star Wars mutations"
fields:
createReview:
args:
episode:
type: "String!"
content:
type: "String!"
rating:
type: "Int!"
type: Episode
resolve: "@=mutation('calculation_mutate_order', [args['calculationId'], ...])"
Resolver
# Resources/services.yml
services:
graphql.starwars.resolver.human:
class: Mefi/GraphQL/Starwars/Resolver/HumanResolver
arguments:
- "@repository.human"
tags:
- { name: overblog_graphql.resolver, alias: "allHumans", method: "resolveAllHumans" }
- { name: overblog_graphql.resolver, alias: "human", method: "resolveHuman" }
define Resolver class
# AppBundle/Resolver/HumanResolver.php
namespace AppBundleResolver;
use OverblogGraphQLBundleDefinitionArgument;
class HumanResolver
{
public function resolveAllHumans(Argument $args): array
{
// Do something with the $args
return $this->humanRepository->findAll();
}
public function resolveHuman(string $humanId): Human
{
try {
return $this->humanRepository->findById($humanId);
} catch (HumanNotFoundException $e) {
throw new UserError('This human was eliminated', 0, $e);
}
}
}
Versioning
/api/v1
/api/v1
/api/v2
/api/v1
/api/v2
/api/v3
No Way!
Just DEPRECATED
HUM?!?
A lot of argue, but that’s it!
Deprecated
# droid.types.yml
Droid:
type: object
config:
fields:
id:
type: "String"
name:
type: "String"
homeWorld:
type: World
interfaces: [Character]
isTypeOf: true
Deprecated
# droid.types.yml
Droid:
type: object
config:
fields:
id:
type: "String"
name:
type: "String"
deprecationReason: "Droids don't deserve names"
homeWorld:
type: World
interfaces: [Character]
isTypeOf: true
Heavy Queries?
Limiting Queries by Depth
Limiting Queries by Depth
/** @var GraphQLValidatorRulesQueryDepth $queryDepth */
$queryDepth = DocumentValidator::getRule('QueryDepth');
$queryDepth->setMaxQueryDepth($maxQueryDepth = 10);
GraphQL::execute(/*...*/);
Limiting Queries by Depth
or with OverBlogGraphQLBundle
Limiting Queries by Depth
or with OverBlogGraphQLBundle
# app/config/config.yml
overblog_graphql:
security:
query_max_depth: 10
Limiting Queries by Complexity
Limiting Queries by Complexity
/** @var GraphQLValidatorRulesQueryComplexity $queryComplexity */
$queryComplexity = DocumentValidator::getRule('QueryComplexity');
$queryComplexity->setMaxQueryComplexity($maxQueryComplexity = 110);
GraphQL::execute(/*...*/);
Limiting Queries by Complexity
or with OverBlogGraphQLBundle
Limiting Queries by Depth
or with OverBlogGraphQLBundle
# app/config/config.yml
overblog_graphql:
security:
query_max_complexity: 1000
Custom field Complexity
# Query.types.yml
Query:
type: object
config:
fields:
droid:
type: "Droid"
args:
id:
description: "id of the droid"
type: "String!"
resolve: "@=resolver('character_droid', [args])"
Custom field Complexity
# Query.types.yml
Query:
type: object
config:
fields:
droid:
type: "Droid"
complexity: '@=1000 + childrenComplexity'
args:
id:
description: "id of the droid"
type: "String!"
resolve: "@=resolver('character_droid', [args])"
Security
Field access control
# human.types.yml
Human:
type: object
config:
fields:
id:
type: "String"
Field access control
# human.types.yml
Human:
type: object
config:
fields:
id:
type: "String"
access: "@=isSuperAdmin()"
Field publicly Visible
# human.types.yml
Human:
type: object
config:
fields:
id:
type: "String"
Field publicly Visible
# human.types.yml
Human:
type: object
config:
fields:
id:
type: "String"
public: "@=service('security.authorization_checker').isGranted('ROLE_ADMIN')"
Links not just for me ;)
https://www.scalablepath.com/blog/how-to-build-graphql-app-php/ - best for
begginers
https://graphql.org/
http://facebook.github.io/graphql/June2018/#sec-Language
https://graphql.org/swapi-graphql/ - play with it!
https://github.com/chentsulin/awesome-graphql
https://www.apollographql.com/
Alex Deemann
alex@lazy-ants.com

More Related Content

PPT
An Introduction to Ruby on Rails 20100506
PPT
An introduction-to-ruby-on-rails
KEY
Motion Django Meetup
PDF
Get cfml Into the Box 2018
PDF
Building Better Web APIs with Rails
PDF
INTERFACE by apidays_Automating style guides for REST, gRPC, or GraphQL by Ph...
PDF
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
PDF
Testing web APIs
An Introduction to Ruby on Rails 20100506
An introduction-to-ruby-on-rails
Motion Django Meetup
Get cfml Into the Box 2018
Building Better Web APIs with Rails
INTERFACE by apidays_Automating style guides for REST, gRPC, or GraphQL by Ph...
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Testing web APIs

What's hot (20)

PDF
Enter the app era with ruby on rails
PDF
Slicing, Dicing, And Linting OpenAPI
PPTX
Build JSON and XML using RABL gem
PDF
Introduction to plugin development
PDF
Annotations in PHP, They Exist.
PPTX
Designing and developing mobile web applications with Mockup, Sencha Touch an...
PDF
Kotlinizeでハマった話
ODP
JavaScript APIs In Focus
PPTX
Prairie DevCon 2015 - Crafting Evolvable API Responses
PDF
Crafting Quality PHP Applications (ConFoo YVR 2017)
PPTX
Building Apis in Scala with Playframework2
PDF
Introducing Spring Auto REST Docs - Spring IO 2017
PDF
Pourquoi Ruby on Rails ça déchire ?
PDF
Build REST API clients for AngularJS
PDF
Crafting Quality PHP Applications (PHP Benelux 2018)
PDF
Deploying a Location-Aware Ember Application
PDF
Dependence day insurgence
PDF
Crafting Quality PHP Applications (Bucharest Tech Week 2017)
PPTX
AngularConf2015
PDF
2010-07-19_rails_tdd_week1
Enter the app era with ruby on rails
Slicing, Dicing, And Linting OpenAPI
Build JSON and XML using RABL gem
Introduction to plugin development
Annotations in PHP, They Exist.
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Kotlinizeでハマった話
JavaScript APIs In Focus
Prairie DevCon 2015 - Crafting Evolvable API Responses
Crafting Quality PHP Applications (ConFoo YVR 2017)
Building Apis in Scala with Playframework2
Introducing Spring Auto REST Docs - Spring IO 2017
Pourquoi Ruby on Rails ça déchire ?
Build REST API clients for AngularJS
Crafting Quality PHP Applications (PHP Benelux 2018)
Deploying a Location-Aware Ember Application
Dependence day insurgence
Crafting Quality PHP Applications (Bucharest Tech Week 2017)
AngularConf2015
2010-07-19_rails_tdd_week1
Ad

Similar to Symfony + GraphQL (20)

PDF
Testing API platform with Behat BDD tests
PDF
apidays LIVE New York - API Code First vs Design First by Phil Sturgeon
PDF
iOS Swift application architecture
PDF
WebNet Conference 2012 - Designing complex applications using html5 and knock...
PDF
Prompt engineering for iOS developers (How LLMs and GenAI work)
PDF
Ams adapters
PDF
Writing a REST Interconnection Library in Swift
PPTX
Golang slidesaudrey
PPTX
Cloud native programming model comparison
PDF
Echtzeitapplikationen mit Elixir und GraphQL
PPTX
MIKE Stack Introduction - MongoDB, io.js, KendoUI, and Express
PDF
Building APIs in an easy way using API Platform
PPT
Smoothing Your Java with DSLs
PDF
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
PDF
Xitrum @ Scala Matsuri Tokyo 2014
PDF
Python RESTful webservices with Python: Flask and Django solutions
PDF
REST easy with API Platform
PDF
Elasticsearch And Apache Lucene For Apache Spark And MLlib
PDF
Cdm mil-18 - hypermedia ap is for headless platforms and data integration
PDF
David Gómez G. - Hypermedia APIs for headless platforms and Data Integration ...
Testing API platform with Behat BDD tests
apidays LIVE New York - API Code First vs Design First by Phil Sturgeon
iOS Swift application architecture
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Prompt engineering for iOS developers (How LLMs and GenAI work)
Ams adapters
Writing a REST Interconnection Library in Swift
Golang slidesaudrey
Cloud native programming model comparison
Echtzeitapplikationen mit Elixir und GraphQL
MIKE Stack Introduction - MongoDB, io.js, KendoUI, and Express
Building APIs in an easy way using API Platform
Smoothing Your Java with DSLs
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum @ Scala Matsuri Tokyo 2014
Python RESTful webservices with Python: Flask and Django solutions
REST easy with API Platform
Elasticsearch And Apache Lucene For Apache Spark And MLlib
Cdm mil-18 - hypermedia ap is for headless platforms and data integration
David Gómez G. - Hypermedia APIs for headless platforms and Data Integration ...
Ad

More from Alex Demchenko (10)

PDF
Kонструируем микросервисную архитектуру на Symfony и связываем с Kong
PDF
How to choose Chatbot platform & wtf is ML, DL, NLP, NLU, CA
PDF
Auto deploy symfony app with codeship and elastic beanstalk
PDF
Symfony2 start
PDF
Twig, что за..
PDF
Symfony2 – reload?
KEY
Symfony camp ua 2010 stats
KEY
Symfony as the platform for open source projects (sympal, apostrophe, diem)
PDF
Routing System In Symfony 1.2
PDF
Symfony Project Publication
Kонструируем микросервисную архитектуру на Symfony и связываем с Kong
How to choose Chatbot platform & wtf is ML, DL, NLP, NLU, CA
Auto deploy symfony app with codeship and elastic beanstalk
Symfony2 start
Twig, что за..
Symfony2 – reload?
Symfony camp ua 2010 stats
Symfony as the platform for open source projects (sympal, apostrophe, diem)
Routing System In Symfony 1.2
Symfony Project Publication

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Smarter Business Operations Powered by IoT Remote Monitoring
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
PDF
Reimagining Insurance: Connected Data for Confident Decisions.pdf
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
Sensors and Actuators in IoT Systems using pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Chapter 2 Digital Image Fundamentals.pdf
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
Cloud computing and distributed systems.
Chapter 3 Spatial Domain Image Processing.pdf
Electronic commerce courselecture one. Pdf
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Dropbox Q2 2025 Financial Results & Investor Presentation
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Smarter Business Operations Powered by IoT Remote Monitoring
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
madgavkar20181017ppt McKinsey Presentation.pdf
Review of recent advances in non-invasive hemoglobin estimation
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
Reimagining Insurance: Connected Data for Confident Decisions.pdf
Advanced Soft Computing BINUS July 2025.pdf
Sensors and Actuators in IoT Systems using pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Chapter 2 Digital Image Fundamentals.pdf
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...

Symfony + GraphQL