Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Building my first GraphQL server in PHP
Search
Davide Fedrigo
July 10, 2019
Programming
1
77
Building my first GraphQL server in PHP
PHP User Group Milan
https://www.meetup.com/MilanoPHP/events/262097221/
Davide Fedrigo
July 10, 2019
Tweet
Share
Other Decks in Programming
See All in Programming
Porting a visionOS App to Android XR
akkeylab
0
590
AI Agent 時代のソフトウェア開発を支える AWS Cloud Development Kit (CDK)
konokenj
3
280
Advanced Micro Frontends: Multi Version/ Framework Scenarios @WAD 2025, Berlin
manfredsteyer
PRO
0
290
テストから始めるAgentic Coding 〜Claude Codeと共に行うTDD〜 / Agentic Coding starts with testing
rkaga
13
4.9k
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
270
Result型で“失敗”を型にするPHPコードの書き方
kajitack
5
930
Systèmes distribués, pour le meilleur et pour le pire - BreizhCamp 2025 - Conférence
slecache
0
120
RailsGirls IZUMO スポンサーLT
16bitidol
0
190
코딩 에이전트 체크리스트: Claude Code ver.
nacyot
0
700
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
270
スタートアップの急成長を支えるプラットフォームエンジニアリングと組織戦略
sutochin26
1
6.2k
ソフトウェア品質を数字で捉える技術。事業成長を支えるシステム品質の マネジメント
takuya542
2
14k
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
351
20k
Agile that works and the tools we love
rasmusluckow
329
21k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
Designing for humans not robots
tammielis
253
25k
Building a Modern Day E-commerce SEO Strategy
aleyda
42
7.4k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.9k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.3k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
Building Applications with DynamoDB
mza
95
6.5k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
Facilitating Awesome Meetings
lara
54
6.4k
Transcript
Building my first GraphQL Building my first GraphQL server in
PHP server in PHP @davidefedrigo
About me About me Software Developer
About me About me Software Developer 2017 Started working with
GraphQL 2017 Started working with GraphQL
About me About me Software Developer 2017 Started working with
GraphQL 2017 Started working with GraphQL 2019 Still in love with it! 2019 Still in love with it!
About me About me Software Developer 2017 Started working with
GraphQL 2017 Started working with GraphQL 2019 Still in love with it! 2019 Still in love with it! linkedin.com/in/davidefedrigo
Agenda Agenda Meet GraphQL From theory to practice PHP libraries
Additional topics
Disclaimer Disclaimer Never done it before! (using PHP)
GraphQL has been released GraphQL has been released only as
a specification only as a specification
A GraphQL service is created by de ning types and
elds on those types type Query { randomMovie: Movie } type Movie { id: Int! title: String! }
A GraphQL service is created by de ning types and
elds on those types Along with functions for each eld on each type type Query { randomMovie: Movie } type Movie { id: Int! title: String! }
GraphQL Query JSON Result { randomMovie { title } }
{ "data": { "randomMovie": { "title": "Back to the Future" } } }
Client-Server Interaction Client-Server Interaction
GraphQL Advantages GraphQL Advantages Declarative Data Fetching Strongly Typed Expressiveness
GraphQL Disadvantages GraphQL Disadvantages Instrumentation Caching
Coding Session Coding Session Minimal Example
User Input User Input By using the type system, it
can be predetermined whether a GraphQL query is valid or not
Field Arguments Field Arguments A way for users to parameterize
queries query { movies(year: 1985) { title(language: "it") } } { "data": { "movies": [ { "title": "Ritorno al Futuro" }, { "title": "I Goonies" } ] } }
Alias Alias query { movies(year:1985) { italianTitle: title(language: "it") englishTitle:
title(language: "en") } } { "data": { "movies": [ { "italianTitle": "Ritorno al Futuro", "englishTitle": "Back to the Future" }, { "italianTitle": "I Goonies", "englishTitle": "The Goonies" } ] } }
Providing Field Argument Values Providing Field Argument Values As Document
Literals As Document Literals query { movies(year: 1985) { title(language: "it") } }
Providing Field Argument Values Providing Field Argument Values As Variables
As Variables query ($year: Int, $language: String) { movies(year: $year) { title(language: $language) } } { "year": 1985, "language": "it" }
Using Enumeration Types Using Enumeration Types A GraphQL enum is
a special type of scalar that has a de ned, nite set of possible values. query ($language: Language) { movies { title(language: $language) } } { "language": "IT" }
User Input Validation User Input Validation query { actors(matching: 1)
{ name } } { "errors": [ { "message": "Field \"actors\" argument \"matching\" requires type String!, found 1.", "extensions": { "category": "graphql" }, "locations": [ { "line": 2, "column": 20 } ] } ] }
Coding Session Coding Session User Input Examples
Abstract Types Abstract Types
type Query { searchMovies(matching: String!): [ Movie! ]! searchTVSeries(matching: String!):
[ TVSeries! ]! }
type Query { searchMovies(matching: String!): [ Movie! ]! searchTVSeries(matching: String!):
[ TVSeries! ]! } query { searchMovies(matching: "game") { title runningTime } searchTVSeries(matching: "game") { title seasons { episodes { runningTime } } } }
Union Types Union Types A GraphQL union type is an
abstract type that represents a set of speci c concrete types
Union Types Union Types type Query { searchMovies(matching: String!): [
Movie! ]! searchTVSeries(matching: String!): [ TvSeries! ]! } type Query { search(matching: String!): [ SearchResult! ]! } union SearchResult = Movie | TvSeries
query { search(matching: "game") { ... on Movie { title
runningTime } ... on TvSeries { title seasons { episodes { runningTime } } } } }
{ "data": { "search": [ { "title": "Avengers: Endgame", "runningTime":
181 }, { "title": "Game of Thrones", "seasons": [ { "episodes": [ { "runningTime": 62 }, { "runningTime": 56 } ] } ] } ] } }
Interfaces Interfaces An Interface is an abstract type that includes
a certain set of elds that a type must include to implement the interface
Interfaces Interfaces interface BasicSearchResult { title: String! } type Movie
implements BasicSearchResult { title: String! runningTime: Int } type TvSeries implements BasicSearchResult { title: String! seasons: [Season!]! }
query { search(matching: "game") { title } } } {
"data": { "search": [ { "title": "Avengers: Endgame" }, { "title": "Game of Thrones" } ] } }
Coding Session Coding Session Abstract Types Examples
Operations Operations
Mutations Mutations type Mutation { rateMovie(movieId: Int!, stars: Int!, comment:
String): MovieReview } type MovieReview { movie: Movie! stars: Int! comment: String }
Modeling Input Objects Modeling Input Objects type Mutation { rateMovie(movieId:
Int!, review: ReviewInput!): MovieReview } input ReviewInput { stars: Int! comment: String }
mutation($movieId: Int!, $review: ReviewInput!) { rateMovie(movieId: $movieId, review: $review) {
movie { title stars } stars } } {"movieId": 1, "review": {"stars": 5, "comment": "Awesome!"}} { "data": { "rateMovie": { "movie": { "title": "Avengers: Endgame", "stars": 4.2 }, "stars": 5, "comment": "Awesome!" } } }
Modeling Input Objects Modeling Input Objects type Mutation { rateMovie(movieId:
Int!, review: ReviewInput!): Review rateTVSeries(tvSeriesId: Int!, review: ReviewInput!): Review } union Review = MovieReview | TvSeriesReview
Modeling Input Objects Modeling Input Objects type Mutation { rate(id:
Int!, showType: Show!, review: ReviewInput!): Review } enum Show { MOVIE TVSERIES DOCUMENTARY }
PHP Libraries PHP Libraries
webonyx/graphql-php webonyx/graphql-php (3175 github stars, 68 contributors) Symfony: overblog/GraphQLBundle Laravel:
rebing/graphql-laravel API Platform relies on it.
youshido-php/GraphQL youshido-php/GraphQL (698 github stars, 34 contributors) Symfony: youshido-php/GraphQLBundle Looking
for Maintainers!
digiaonline/graphql-php digiaonline/graphql-php (190 github stars, 9 contributors)
lighthouse-php.com lighthouse-php.com (1031 github stars, 59 contributors) Lighthouse is a
PHP package that allows you to serve a GraphQL endpoint from your Laravel application
GraphQL Clients GraphQL Clients
GraphiQL GraphiQL
GraphQL Playground GraphQL Playground GraphQL Playground is a graphical, interactive,
in- browser GraphQL IDE. Integrated with Apollo Server.
Insomnia Insomnia
Postman Postman
Additional Interesting Topics Additional Interesting Topics
Additional Interesting Topics Additional Interesting Topics Errors and exceptions
Additional Interesting Topics Additional Interesting Topics Errors and exceptions Keep
resolvers and domain logic separated
Additional Interesting Topics Additional Interesting Topics Errors and exceptions Keep
resolvers and domain logic separated N+1 problem
Additional Interesting Topics Additional Interesting Topics Errors and exceptions Keep
resolvers and domain logic separated N+1 problem Authentication
Additional Interesting Topics Additional Interesting Topics Errors and exceptions Keep
resolvers and domain logic separated N+1 problem Authentication Testing
Additional Interesting Topics Additional Interesting Topics Errors and exceptions Keep
resolvers and domain logic separated N+1 problem Authentication Testing Custom Scalar Types
Questions? Questions?
Thank you! Thank you! github.com/davidefedrigo/graphql-pug