Learn GraphQL by Examples
June 2018 SpecificationGraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. It provides a complete and understandable description of the data in your API.
These examples cover the fundamental concepts of GraphQL, from writing basic queries and defining schemas to understanding types and resolvers. You will learn how to structure your data requirements efficiently.
Query Operations
Fetching data from GraphQL APIs with this sample code demonstrating query operation syntax, field selection for precise data requirements, response structure matching query shape, and shorthand versus explicit query keyword usage.
Nested Field Selection
Traversing object relationships with this code example showing selection sets for nested objects, hierarchical data fetching in single requests, avoiding under-fetching with related data, and client-driven data requirements.
Field Arguments
Passing parameters to fields with this sample code demonstrating argument syntax using parentheses, filtering and modifying results with arguments, nested field arguments for granular control, and server-side transformations.
Scalar Types
Defining primitive data types with this code example showing built-in scalar types including ID, String, Int, Float, and Boolean, scalar type characteristics as leaf values, custom scalar capabilities, and serialization behavior.
List Types
Returning collections of values with this sample code demonstrating list type syntax using square brackets, combining lists with non-null modifiers, nullability control at different levels, and querying list fields with selection sets.
Non-Null Modifier
Enforcing required fields with this code example showing exclamation mark syntax for non-null types, error bubbling behavior when null returned, required arguments with non-null modifier, and schema validation guarantees.
Resolvers
Implementing data fetching logic with this sample code demonstrating resolver function structure, four resolver arguments including parent and args, resolver mapping matching schema structure, and trivial resolution for matching properties.

