You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: site/index.html.js
+4-167Lines changed: 4 additions & 167 deletions
Original file line number
Diff line number
Diff line change
@@ -344,7 +344,7 @@ type Species {
344
344
345
345
<sectionclassName="point6">
346
346
<divclassName="prose">
347
-
<h2>Powered by your<br/>existing data and code</h2>
347
+
<h2>Fulfilled with your<br/>existing data and code</h2>
348
348
{/*Illustration of each field becoming a function?]*/}
349
349
<p>
350
350
GraphQL creates a uniform, powerful API across the entire surface
@@ -357,174 +357,11 @@ type Species {
357
357
</div>
358
358
</section>
359
359
360
-
{/*
361
-
<section className="marketing-row">
362
-
<div className="marketing-col">
363
-
<h3>Declarative</h3>
364
-
<p>
365
-
{`Query responses are decided by the client rather
366
-
than the server. A GraphQL query returns exactly what a client
367
-
asks for and no more.`}
368
-
</p>
369
-
</div>
370
-
<div className="marketing-col">
371
-
<h3>Compositional</h3>
372
-
<p>
373
-
{`A GraphQL query itself is a hierarchical set of fields. The
374
-
query is shaped just like the data it returns. It is a natural
375
-
way for product engineers to describe data requirements.`}
376
-
</p>
377
-
</div>
378
-
<div className="marketing-col">
379
-
<h3>Strong-typed</h3>
380
-
<p>
381
-
{`A GraphQL query can be ensured to be valid within a GraphQL type
382
-
system at development time allowing the server to make
383
-
guarantees about the response. This makes it easier to build
384
-
high-quality client tools.`}
385
-
</p>
386
-
</div>
387
-
</section>
388
-
389
-
<hr className="home-divider" />
390
-
391
-
<section className="home-content">
392
-
<Marked>{`
393
-
394
-
GraphQL is a data query language and runtime designed and used at
395
-
Facebook to request and deliver data to mobile and web apps since 2012.
396
-
397
-
When we built Facebook's mobile applications, we needed a data-fetching
398
-
API powerful enough to describe all of Facebook, yet simple enough to
399
-
be easy to learn and use by our product developers. We developed
400
-
GraphQL in 2012 to fill this need. Today it is the primary way we build
401
-
client apps and the servers that drive them.
402
-
403
-
We've begun the process of open-sourcing GraphQL by drafting a
404
-
specification, releasing a reference implementation, building tools,
405
-
and forming a community around it here at graphql.org.
406
-
407
-
The reference implementation, [graphql-js](https://github.com/graphql/graphql-js)
408
-
provides a library in JavaScript that is the basis for full GraphQL
409
-
implementations and tools. It is not a fully standalone GraphQL server
410
-
that a client developer could use to start manipulating and querying
411
-
data. Most importantly it provides no mapping to a functioning,
412
-
production-ready backend. For those using an express server, we recommend
413
-
using [express-graphql](https://github.com/graphql/express-graphql) to
414
-
provide a GraphQL server.
415
-
416
-
Despite being widely used at Facebook, open source GraphQL is still a
417
-
new technology undergoing changes. Many of the tools and integrations
418
-
with various languages and data storage engines have not yet been built,
419
-
and in many cases are [already being built](https://www.npmjs.com/search?q=graphql).
420
-
421
-
`}</Marked>
422
-
423
-
<hr className="home-divider" />
424
-
425
-
<Marked>{`
426
-
427
-
A GraphQL query is a string interpreted by a server that returns data in a specified format. Here is an example query:
428
-
429
-
{
430
-
user(id: 3500401) {
431
-
id,
432
-
name,
433
-
isViewerFriend,
434
-
profilePicture(size: 50) {
435
-
uri,
436
-
width,
437
-
height
438
-
}
439
-
}
440
-
}
441
-
442
-
And here is the response to that query.
443
-
444
-
{
445
-
"user" : {
446
-
"id": 3500401,
447
-
"name": "Jing Chen",
448
-
"isViewerFriend": true,
449
-
"profilePicture": {
450
-
"uri": "http://someurl.cdn/pic.jpg",
451
-
"width": 50,
452
-
"height": 50
453
-
}
454
-
}
455
-
}
456
-
457
-
Even a simple example shows many of its design principles:
458
-
459
-
**Hierarchical:** Most product development today involves the creation and manipulation of view hierarchies. To achieve congruence with the structure of these applications, a GraphQL query itself is a hierarchical set of fields. The query is shaped just like the data it returns. It is a natural way for product engineers to describe data requirements.
460
-
461
-
**Product-centric:** GraphQL is unapologetically driven by the requirements of views and the front-end engineers that write them. We start with their way of thinking and requirements and build the language and runtime necessary to enable that.
462
-
463
-
**Client-specified queries:** In GraphQL, the specification for queries are encoded in the client rather than the server. These queries are specified at field-level granularity. In the vast majority of applications written without GraphQL, the server determines the data returned in its various scripted endpoints. A GraphQL query, on the other hand, returns exactly what a client asks for and no more.
464
-
465
-
**Backwards Compatible:** In a world of deployed native mobile applications with no forced upgrades, backwards compatibility is a challenge. Facebook, for example, releases apps on a two week fixed cycle and pledges to maintain those apps for at least two years. This means there are at a minimum 52 versions of our clients per platform querying our servers at any given time. Client-specified queries simplifies managing our backwards compatibility guarantees.
466
-
467
-
**Structured, Arbitrary Code:** Query languages with field-level granularity have typically queried storage engines directly, such as SQL. GraphQL instead imposes a structure onto a server, and exposes fields that are backed by arbitrary code. This allows for both server-side flexibility and a uniform, powerful API across the entire surface area of an application.
468
-
469
-
**Application-Layer Protocol:** GraphQL is an application-layer protocol and does not require a particular transport. It is a string that is parsed and interpreted by a server.
470
-
471
-
**Strongly-typed:** GraphQL is strongly-typed. Given a query, tooling can ensure that the query is both syntactically correct and valid within the GraphQL type system before execution, i.e. at development time, and the server can make certain guarantees about the shape and nature of the response. This makes it easier to build high quality client tools.
472
-
473
-
**Introspective:** GraphQL is introspective. Clients and tools can query the type system using the GraphQL syntax itself. This is a powerful platform for building tools and client software, such as automatic parsing of incoming data into strongly-typed interfaces. It is especially useful in statically typed languages such as Swift, Objective-C and Java, as it obviates the need for repetitive and error-prone code to shuffle raw, untyped JSON into strongly-typed business objects.
474
-
475
-
## Why invent something new?
476
-
477
-
Obviously GraphQL is not the first system to manage client-server interactions. In today's world there are two dominant architectural styles for client-server interaction: REST and ad hoc endpoints.
478
-
479
-
### REST
480
-
481
-
REST, an acronym for Representational State Transfer, is an architectural style rather than a formal protocol. While there is much debate about what exactly is REST and is not, we wish to avoid these debates. We are interested in the typical attributes of systems that self-identify as REST, rather than systems which are formally REST.
482
-
483
-
Objects in a typical REST system are addressable by URI and interacted with using verbs in the HTTP protocol. An HTTP GET to a particular URI fetches an object and returns a server-specified set of fields. An HTTP PUT edits an object; an HTTP DELETE deletes an object; and so on.
484
-
485
-
We believe there are a number of weaknesses in typical REST systems, ones that are particularly problematic in mobile applications:
486
-
487
-
* Fetching complicated object graphs require multiple round trips between the client and server to render single views. For mobile applications operating in variable network conditions, these multiple roundtrips are highly undesirable.
488
-
* Invariably, fields and additional data are added to REST endpoints as the system requirements change. However, old clients also receive this additional data as well, because the data fetching specification is encoded on the server rather than the client. As result, these payloads tend to grow over time for all clients. When this becomes a problem for a system, one solution is to overlay a versioning system onto the REST endpoints. Versioning also complicates a server, and results in code duplication, spaghetti code, or a sophisticated, hand-rolled infrastructure to manage it. Another solution to limit over-fetching is to provide multiple views – such as “compact” vs “full” – of the same REST endpoint. However, this coarse granularity often does not offer adequate flexibility.
489
-
* REST endpoints are usually weakly-typed and lack machine-readable metadata. While there is much debate about the merits of strong- versus weak-typing in distributed systems, we believe in strong typing because of the correctness guarantees and tooling opportunities it provides. Developers deal with systems that lack this metadata by inspecting frequently out-of-date documentation and then writing code against the documentation.
490
-
* Many of these attributes are linked to the fact that “REST is intended for long-lived network-based applications that span multiple organizations” according to its inventor. This is not a requirement for APIs that serve a client app built within the same organization.
491
-
492
-
Nearly all externally facing REST APIs we know of trend towards or end up in these non-ideal states, as well as nearly all internal REST APIs. The consequences of opaqueness and over-fetching are more severe in internal APIs since their velocity of change and level of usage is almost always higher.
493
-
494
-
Because of multiple round-trips and over-fetching, applications built in the REST style inevitably end up building ad hoc endpoints that are superficially in the REST style. These actually couple the data to a particular view which explicitly violates one of REST's major goals. Most REST systems of any complexity end up as a continuum of endpoints that span from “traditional” REST to ad hoc endpoints.
495
-
496
-
### Ad Hoc Endpoints
497
-
498
-
Many applications have no formalized client-server contract. Product developers access server capabilities through ad hoc endpoints and write custom code to fetch the data they need. Servers define procedures, and they return data. This approach has the virtue of simplicity, but can often become untenable as systems age.
499
-
500
-
* These systems typically define a custom endpoint per view. For systems with a wide surface area this can quickly grow into a maintenance nightmare of orphaned endpoints, inconsistent tooling, and massive server code duplication. Disciplined engineering organizations can mitigate these issues with great engineering practices, high quality abstractions, and custom tooling. However, given our experience we believe that custom endpoints tend to lead to entropic server codebases.
501
-
* Much like REST, the payloads of custom endpoints grow monotonically (even with mitigation from versioning systems) as the server evolves. Deployed clients cannot break, and, with rapid release cycles and backwards compatibility guarantees, distributed applications will have large numbers of extant versions. Under these constraints it is difficult to remove data from a custom endpoint.
502
-
* Custom endpoints tend to create a clunky, multi-language, multi-environment development process for a client developer. No matter if the data has been accessed before in a different view, they are required to first change the custom endpoint, then deploy that code to a server accessible from a mobile device, and only then change the client to utilize that data. In GraphQL – unless the data in the view is completely new to the entire system – a product developer adds a field to a GraphQL query and the work on the client continues unabated.
503
-
* Much like REST, most systems with custom endpoints do not have a formalized type system, which eliminates the possibility for the tools and guarantees that introspective type systems can provide. Some custom-endpoint-driven systems do use a strongly typed serialization scheme, such as Protocol Buffers, Thrift, or XML. Those do allow for direct parsing of responses into typed classes and eliminating boilerplate shuffling from JSON into handwritten classes. These systems are as not as expressive and flexible as GraphQL, and the other downsides of ad hoc endpoints remain.
504
-
505
-
We believe that GraphQL represents a novel way of structuring the client-server contract. Servers publish a type system specific to their application, and GraphQL provides a unified language to query data within the constraints of that type system. That language allows product developers to express data requirements in a form natural to them: a declarative and hierarchal one.
506
-
507
-
This is a liberating platform for product developers. With GraphQL, no more contending with ad hoc endpoints or object retrieval with multiple roundtrips to access server data; instead an elegant, hierarchical, declarative query dispatched to a single endpoint. No more frequent jumps between client and server development environments to do experimentation, or to change or create views of existing data; instead experiments are done and new views are built within a native, client development environment exclusively. No more shuffling unstructured data from ad hoc endpoints into business objects; instead, you have a powerful, introspective type system that serves as a platform for tool building.
508
-
509
-
Product developers are free to focus on their client software and requirements while rarely leaving their development environment. They can more confidently support shipped clients as a system evolves; and they are using a protocol designed to operate well within the constraints of mobile applications. Product developers can query for exactly what they want, in the way they think about it, across their entire application's data model.
0 commit comments