Top Banner
GraphQL Introduction Serge Huber, Jahia CTO [email protected] #graphql Make some noise
25

GraphQL Introduction

Apr 14, 2017

Download

Technology

Serge Huber
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: GraphQL Introduction

GraphQL IntroductionSerge Huber, Jahia CTO

[email protected]

#graphqlMake some noise

Page 2: GraphQL Introduction

1WHAT IS GRAPHQL ?

…and what it isn’t.

Page 3: GraphQL Introduction

1 WHAT IS GRAPHQL ?I like opposites

It is not:• A query language like SQL, JCR-SQL,

etc…• A URL specification• A finalized standard• A standard submitted to a standards

body• A 100% JSON standard• A mature standard, changes are still

happening

Page 4: GraphQL Introduction

1 WHAT IS GRAPHQL ?A (very) quick look

Courtesy of the GraphQL.org home page

Page 5: GraphQL Introduction

1 WHAT IS GRAPHQL ?Some users

Courtesy of the GraphQL.org home page

See more on http://graphql.org/users

Page 6: GraphQL Introduction

1 WHAT IS GRAPHQL ?A quick demo

https://www.graphqlhub.com

Page 7: GraphQL Introduction

1 WHAT IS GRAPHQL ?Schemas• A schema that describes: • Objects• Object fields• Field arguments & directives• Interfaces• Unions

Page 8: GraphQL Introduction

1 WHAT IS GRAPHQL ?Fields, the key to understanding GraphQL !A field may be:• a static value• a value resolved through

code

Field may have:• Arguments that are like

parameters to a method call• Constraints to filter data• Directives that make the field

conditional in the result

Don’t think of fields as variables, think of them as methods !

Page 9: GraphQL Introduction

1 WHAT IS GRAPHQL ?Queries• Queries• Specify what fields are part of

the result• Only fields specified in the

schema are acceptable• Field may be the result of

computations• Fields may specify arguments

that will constrain the results (such as id:10)

• Directives may also be used (such as @include)

• Variables may be used• Fragments• Type casts !• Pagination (Relay schema)

Page 10: GraphQL Introduction

1 WHAT IS GRAPHQL ?Mutations• Mutations• Make it possible to

write/modify data• Very similar syntax to

queries

Page 11: GraphQL Introduction

1 WHAT IS GRAPHQL ?Compared to REST APIs

REST GraphQL

Specifies URL structure YES NO

Specifies request / response body structure NO YES

Validation NO YES

Requires a declared schema NO YES

Key-Value friendly YES NO

Extra (non CRUD) methods standardized NO YES

Page 12: GraphQL Introduction

2GRAPHQL INTEGRATION

Mapping to existing stuff

Page 13: GraphQL Introduction

2 GRAPHQL INTEGRATIONTypical architecture

Client

Server

React / React Native

Relay

GraphQL

Data & Services

Page 14: GraphQL Introduction

2 GRAPHQL INTEGRATIONRelay

Page 15: GraphQL Introduction

2 GRAPHQL INTEGRATIONAngular 2 and Relay

https://tech.small-improvements.com/2016/02/25/angular-2-and-relay/

Page 16: GraphQL Introduction

2 GRAPHQL INTEGRATIONJava Libraries

• graphql-java : Java implementation of GraphQL

• graphql-java-servlet : A relay-compatible OSGI Java servlet

• graphql-java-annotations : Can generate GraphQL schemas from Pojo annotations !

Page 17: GraphQL Introduction

3GRAPHQL TOOLINGWhat there’s tooling already ?

Page 18: GraphQL Introduction

3 GRAPHQL TOOLINGGraphiQL

Page 19: GraphQL Introduction

3 GRAPHQL TOOLINGGraphiQL

Features• Auto-completion based on GraphQL

schema• Execution of GraphQL queries and

mutations• Input of variables• Result viewer• Built-in documentation browser

Page 20: GraphQL Introduction

3 GRAPHQL TOOLINGGraphQLHubA hub to test public GraphQL services such as :• Hacker News• Reddit• GitHub• Twitter• Giphy• Relay-compatible Key-

Value store

But (strangely) not Facebook (probably because of API keys)

Page 21: GraphQL Introduction

3 GRAPHQL TOOLINGAwesome GraphQLBest list of tools & libraries at :

https://github.com/chentsulin/awesome-graphql

Some cool examples:

SQL Libraries• GraphpostgresQL - GraphQL for Postgres.• sql-to-graphql - Generate a GraphQL API based on your SQL

database structure.• PostGraphQL - A GraphQL schema created by reflection over a

PostgreSQL schema.

Page 22: GraphQL Introduction

4DX INTEGRATION DEMO

You’re not serious are you ?

Page 23: GraphQL Introduction

4 DX INTEGRATION DEMOThe sourceProject available here:

http://www.github.com/Jahia/graphql-core-feature

• Built as a Karaf features, requires DX 7.2 to run• Embeds GraphiQL as an administration UI !• Extensible through other modules, they simply provide query and

mutation providers !• Dynamic schema, re-generated every time a new mutation or query

provider is registered in the OSGi services registry• Based on the graphql-java-servlet project, available at:

http://www.github.com/graphql/graphql-java-servlet• Still a lot to do, just beginning• Code is clearly a proof of concept prototype, lots of things will need

cleaning up and refactoring• Mapping to JCR content still to be defined.

Page 24: GraphQL Introduction

5 QUESTIONS AND ANSWERSAsk away, don’t be shy