GraphQL or Bust v2.2
GraphQL or Bust v2.2
GraphQL or Bust v2.2
Nordic APIs
© 2017 - 2022 Nordic APIs
Also By Nordic APIs
Developing the API Mindset
The API Lifecycle
Securing The API Stronghold
API-Driven DevOps
The API Economy
Programming APIs with the Spark Web Framework
How to Successfully Market an API
API Design on the Scale of Decades
API Strategy for Open Banking
Identity And APIs
API as a Product
Developer Experience
This release is dedicated to the over 30 thought leaders that
have contributed to the Nordic APIs blog over the past few
years!
Contents
Supported by Curity . . . . . . . . . . . . . . . . . . i
8: GraphQL Network . . . . . . . . . . . . . . . . . . 95
9: Graphcool . . . . . . . . . . . . . . . . . . . . . . . 96
10: Optics by Apollo . . . . . . . . . . . . . . . . . . 97
Final Thoughts . . . . . . . . . . . . . . . . . . . . . . 98
Resources . . . . . . . . . . . . . . . . . . . . . . . . . 99
Endnotes . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
CONTENTS i
Supported by Curity
curity.io.
Preface: Introduction to
GraphQL
Within the last couple of years, there has been a resur-
gence of discussion around API design standards such
as REST, gRPC, GraphQL, and many others. While the
Representational State Transfer (REST) methodology has
been a perfect fit for many web APIs - for the past decade
or more in some cases - some developers see operational
improvements within nuanced methods that break from
these original constructs.
Over/Under Fetching
REST suffers from the fact that it’s often used for some-
thing it wasn’t really designed for, and as a result, it often
must be heavily modified. That’s not to say that REST
doesn’t have its place — it’s only to say that it may not
be the best solution for serving client applications. As
Facebook says in its own documentation:
Is GraphQL The End of REST Style APIs? 5
Now that we’ve seen the issues with REST, how, exactly,
does GraphQL solve them?
Conclusion
What is GraphQL
type Project {
name: String
tagline: String
contributors: [User]
}
{
project(name: "GraphQL") {
tagline
}
}
{
"project": {
"tagline": "A query language for APIs"
}
}
{
latestPost {
_id,
title,
content,
author {
name
},
comments {
content,
author {
name
}
}
}
}
the consumer.
4 - GraphQL Is a Specification
5 - GraphQL Improves
Understanding and Organization
Who Uses It
Conclusion: Assess
What is GraphQL?
type Project {
name: String
tagline: String
contributors: [User]
}
project(name: "GraphQL") {
tagline
}
}
{
"project": {
"tagline": "A query language for APIs"
}
}
How to Wrap a REST API in GraphQL 24
Defining a Schema
import {
GraphQLList,
GraphQLObjectType,
GraphQLSchema,
GraphQLString,
} from 'graphql';
function fetchResponseByURL(relativeURL) {
return fetch(`${BASE_URL}${relativeURL}`).then(res => r\
es.json());
}
function fetchPeople() {
return fetchResponseByURL('/people/').then(json => json\
.people);
}
function fetchPersonByURL(relativeURL) {
return fetchResponseByURL(relativeURL).then(json => jso\
n.person);
}
app.use('/graphql', wrapper.expressMiddleware())
npm i graphql-rest-wrapper
app.use([ROUTE], wrapper.expressMiddleware())
fetch("http://localhost:9090/graphql",
{
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: "POST",
body: "{'query': 'query { MyRestAPI { id, name } \
}'}"
})
.then(function (res) {
console.log(res);
})
How to Wrap a REST API in GraphQL 30
Dogma vs Practices
API Versioning
Pagination
Accept-Encoding: gzip
Conclusion
this adoption.
GraphQL is a paradigm shift in many ways — and with
that, security concerns have changed. While some secu-
rity concerns have gone away, replaced by architectural
differences and nuances, other concerns have been am-
plified.
In this piece, we’re going to talk about those issues, high-
lighting some general concerns in regards to security
in an API system supporting GraphQL. While GraphQL
itself is not the primary driver of these concerns, these
issues should be addressed within the greater frame
of a GraphQL system, and all of the implications that
suggests.
GraphQL - A Summary
Unified Failures
Measured Optimism
Parallel Execution
Request Budgeting
Service Caching
Final Thoughts
implementation.
For situations like that faced by Yelp, however, GraphQL
fits perfectly and solves the major issues at hand. For
this reason alone, should developers find themselves in
a microservice architecture and requiring a greater flex-
ibility in data delivery and structuring, GraphQL should
absolutely be a top consideration.
Comparing GraphQL
With Other Methods to
Tether API Calls
Use Cases
Alternatives — GraphQL
{
latestPost {
_id,
title,
content,
author {
name
},
comments {
content,
author {
name
}
}
}
}
Conclusions
What is Relay?
The Good
{
user(id:1) {
name
title
avatarUrl
timezone
locale
lastSeenOnline
email
phone
Location
accountOwner {
name
avatarUrl
}
tags {
edges {
node {
label
color
}
}
}
accountUsers(first:10) {
The Power of Relay: The Entry Point to GraphQL 74
edges {
node {
id
avatarUrl
}
}
pageInfo {
totalAccountUsers
}
}
recentConversations(first:10) {
edges {
node {
lastMessage
updatedAt
status
}
pageInfo {
totalConversationCount
}
}
}
}
}
Their reaction?
The Bad
A REST Replacement
Conclusion
1: GraphQL Hub
2: Brandfolder
3: Buildkite
4: EHRI
5: GDOM
6: GitHub
9: melodyCLI
10: SuperChargers.io
11: Microsoft
More Resources:
1: GraphiQL
3: GraphCMS
GraphCMS
5: GraphQL Faker
type Person {
name: String @fake(type: firstName)
gender: String @examples(values: ["male", "female"])
}
6: Swagger to GraphQL
7: GraphQL IDE
8: GraphQL Network
9: Graphcool
Screenshot of the Graphcool console, where you can add new fields and
data relations.
10 Tools and Extensions For GraphQL APIs 97
Final Thoughts
Resources
Background
For those who don’t know what GraphQL is, it can broadly
be summarized as an application layer query language.
GraphQL interprets strings from the client, and returns
data in an understandable, predictable, pre-defined man-
ner. This is a very short, summarized explanation of what
GraphQL does, but there is so much more that makes it
special – for a more complete summary, check out our
piece on the potential benefits of GraphQL adoption.
What is more important to this discussion is how GraphQL
was created. After internal development began in 2012 at
Facebook, GraphQL was released publicly in 2015, offer-
ing an alternative to the dominant architectures of the API
space, notably REST.
GraphQL was initially developed to help Facebook cope
with challenges in fetching specific data from their collec-
tion of services without introducing bloat and complexity.
By allowing the client to define the expected data for-
mat, Facebook, through GraphQL, was able to design a
What The GraphQL Patent Release Means For the API Industry 102
There’s still some cause for concern around the new li-
censing scheme, however. Facebook has broadly adopted
the MIT license, which doesn’t expressly include a patent
grant. There was some concern expressed, such as that
of RedMonk founder Stephen O’Grady, that adopting MIT
over the Apache license, which gave a more clear patent
situation to developers, created new concerns:
Is This a Concern?
Final Thoughts
So what does this all mean for the API space? It’s easy to
assign nefarious intent to Facebook, but the reality is that
Facebook is a public company – as many companies in
the API community now are. This means that they have
certain concerns that they need to address, and certain
expectations concerning the use of their applications and
codebase.
That being said, stifling open source implementations is
a significant issue – and while that’s not what’s happen-
ing in this case, the reactions of some providers to the
relicensing (such as dropping GraphQL in fear of possible
legal issues) is understandable. That should be the take-
away to all of this – while there are concerns about patent
licenses within the GraphQL license language, much of
the fear is based on conjecture, and if the possibility of
future concern is significant enough to worry an organi-
zation, they should consider moving away from GraphQL
and into a more open-source friendly, freely licensed
alternative.
What The GraphQL Patent Release Means For the API Industry 108
Stay Connected
Nordic APIs AB ©
Facebook | Twitter | Linkedin | Google+ | YouTube
Blog | Home | Newsletter | Contact