History
Facebook started GraphQL development in 2012 and released a draft specification and reference implementation as open source in 2015. In 2018, GraphQL was moved to the newly established GraphQL Foundation, hosted by the non-profit Linux Foundation. On February 9, 2018, the GraphQL Schema Definition Language became part of the specification. Many popular public APIs adopted GraphQL as the default way to access them. These include public APIs of Facebook, GitHub, Yelp, Shopify, Google Directions API and many others. There is an annual GraphQL Conference featuring new developments of the protocol and organizations successfully using GraphQL. The event is hosted by the GraphQL Foundation with previous organizers incl. Prisma, Hygraph, Commercetools.
Design
GraphQL supports reading, writing (mutating), and subscribing to changes to data (realtime updates – commonly implemented using WebSockets). A GraphQL service is created by defining types with fields, then providing functions to resolve the data for each field. The types and fields make up what is known as the schema definition. The functions that retrieve and map the data are called resolvers. After being validated against the schema, a GraphQL query is executed by the server. The server returns a result that mirrors the shape of the original query, typically as JSON. Type system Schema of swapi-graphql rendered as a graph by GraphQL Voyager With GraphQL, a business domain is modeled as a graph by defining a schema; within this schema, different types of nodes and their relations are defined. The GraphQL type system describes what data can be queried from the API. The collection of those capabilities is referred to as the service's schema and clients can use that schema to send queries to the API that return predictable results. The root type of a GraphQL schema, Query by default, contains all of the fields that can be queried. Other types define the objects and fields that the GraphQL server can return. There are several base types, called scalars, to represent things like strings, numbers, and IDs. Fields are defined as nullable by default, and a trailing exclamation mark can be used to make a field non-nullable (required). A field can be defined as a list by wrapping the field's type in square brackets (for example, authors: [String]).type Query type User Queries A GraphQL query defines the exact shape of the data needed by the client.query CurrentUser Once validated and executed by the GraphQL server, the data is returned in the same shape.{ "currentUser": { "name
Testing
GraphQL APIs can be tested manually or with automated tools issuing GraphQL requests and verifying the correctness of the results. Automatic test generation is also possible. New requests may be produced through search-based techniques due to a typed schema and introspection capabilities. Some of the software tools used for testing GraphQL implementations include Postman, Beeceptor, GraphiQL, Apollo Studio, GraphQL Hive, GraphQL Editor, and Step CI.