The 4th Weekly company-internal Agilize DevTalk of November, 2017.
GETTING STARTEDWITH GraphQLAgilize Cloud Accounting, 24/11/2017Weekly company-internal DevTalks
View Slide
Hallo!I’M THIAGO COLARESAgile managerFull stack developerOpen sourceCo-founder @ Agilize Cloud Accounting@thicolares
1.DEFINE: GraphQL
WHAT IS GRAPHQL○ Declarative data fetching○ Alternative to REST○ Single endpoint → responds to queries
/authors//authors//books/authors//followers3 ENDPOINTS
queryqueryquery1 SINGLEENDPOINT
DEMO 1
2.CHARACTERISTICS
GraphQL TIMELINE○ Developed by Facebook on 2012○ Presented → React.js Conf 2015○ Is not for React Developers○ Other companies had the same initiative○ Netflix → Falcor○ Cousera → Now uses GraphQL
REST CHALLENGES○ Need for efficient data loading (mobile)○ Variety of different frontend frameworks○ Rapid feature development
GraphQL BENEFITS○ No mover over or underfetching○ Almost non API if the interface changes○ Faster feedbacks cycles
INSIGHTFUL ANALYTICS○ Fine-grained info about what read data○ Evolving and deprecating API
3.KEY CONCEPTS
type Query {...}type Mutation {...}type Subscription {...}ROOT TYPE
query {User(id: 123) {nameposts {title}}}QUERYHTTP POST
{"data": {"User": {"name": "Joston Muriel","posts": [{title: "Hello, it's me"}{title: "Lines in the sand"}]}}}RESPONSERESPONSE
SCHEMA○ Strong type system○ Schema as client-server contract○ Client and server can work independently○ Schema Definition Language
type Person {name: String!age: Int!}DEFINING SIMPLE TYPES! → required
type Person {name: String!age: Int!}ADDING A RELATIONtype Post {title: String!author: Person!}
type Person {name: String!age: Int!posts: [Post!]!}ADDING A HAS-MANY RELATIONtype Post {title: String!author: Person!}
DEMO 2
4.MUTATIONS
WRITING DATA WITH MUTATIONS○ A query too○ You can ask for the returning fields○ Even nested ones
3 KINDS OF MUTATIONS○ creating new data○ updating existing data○ deleting existing data
A MUTATIONmutation {createPerson(name: "Bob", age: 36) {nameage}}Similar syntax. Mutation keyword. Special root field.
DEFINING A MUTATIONtype Mutation {createPerson(name: String!, age: String!) Person!...}
5.NODE EXAMPLE
DEMO 3
“Nescit cedere
THANKS!Thiago Colares@thicolares