This document introduces GraphQL, describing what it is and isn't. It explains that GraphQL is not a query language like SQL, but rather specifies fields that can be resolved through code. The document provides examples of GraphQL schemas, queries, and mutations. It also discusses GraphQL integration with various technologies like Relay and Java libraries. Finally, it demonstrates GraphQL tooling like GraphiQL and an example DX integration.
3. 3
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
4. 4
WHAT IS GRAPHQL ?
A (very) quick look
Courtesy of the GraphQL.org home page
5. 5
WHAT IS GRAPHQL ?
Some users
Courtesy of the GraphQL.org home page
See more on http://graphql.org/users
7. 7
WHAT IS GRAPHQL ?
Schemas
• A schema that describes:
• Objects
• Object fields
• Field arguments & directives
• Interfaces
• Unions
8. 8
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 !
9. 9
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)
10. 10
WHAT IS GRAPHQL ?
Mutations
• Mutations
• Make it possible to write/modify
data
• Very similar syntax to queries
11. 11
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
20. 20
GRAPHQL TOOLING
GraphQLHub
A 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)
21. 21
GRAPHQL TOOLING
Awesome GraphQL
Best 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.
23. 23
DX INTEGRATION DEMO
The source
Project 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.