Chapter 2. The GraphQL Specification

A specification allows all parties to work together with a common language and syntax. Specifications are everywhere. Motorists drive their cars on the same side of the road, obey stop lights, obey posted road signs, and follow other local regulations. Without clearly defined rules, traffic collisions would happen everywhere. Written languages are an example of another specification, with Arabic and Hebrew specifications calling for text to be written right to left, whereas English and German specifications call for text to be written left to right.

In the technology realm, some common technologies have a specification and some do not. XML has a very strict standard. From the formal specification, you’ll find many examples like this:

The formal grammar of XML is given in this specification using a simple Extended Backus-Naur Form (EBNF) notation. Each rule in the grammar defines one symbol, in the form

symbol ::= expression

Symbols are written with an initial capital letter if they are the start symbol of a regular language, otherwise with an initial lowercase letter. Literal strings are quoted.

Any human or software that writes or reads an XML document can make sure the document is valid because there’s a strict specification.

As previously discussed, REST doesn’t have a specification. A REST endpoint can return a response in a specific standards-compliant version of JSON or XML, but you’ll find little agreement across REST endpoints on how ...

Get GraphQL for Modern Commerce now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.