Table of Contents
IntroductionScott Moss defines GraphQL as a declarative query language, explains how GraphQL works both on the client and the server side.
SchemasScott explains that in order to create a GraphQL server, a schema must first be created using a schema definition language, or SDL, and reviews the basic parts of a schema.
GraphQL ServerScott demonstrates how to build a basic GraphQL server by coding typeDefs, resolvers, and an Apollo server. The goal of this section is to demonstrate the simple way GraphQL functions before diving into more detailed explanations.
Queries & Resolvers
Query TypesScott defines query types as object types, and demonstrates how to build a query. Questions from the audience about syntax and the use of queries are also answered.
ResolversScott defines resolvers as functions responsible for returning values for fields on a type, and explains that to create a server with GraphQL a query type with a field and a resolver for that field are needed.
Query Types ExerciseAfter Scott walks through the code repository and specifies which files will be updated over the course of the workshop, students are instructed to create a query type based off an array.
Query Types SolutionScott live codes the solution to the query types exercise.
Resolvers Q&AScott explains that each field has its own resolver, demonstrates what default resolvers are, and answers questions from the audience about top level and field specific resolvers.
Arguments & Input Types
ArgumentsScott explains that arguments allow clients to pass variables along with queries, and that they can be used in resolvers to get data. Arguments must be defined in the schema, but can be added to any field.
Input TypesScott defines input types as types for arguments, and how all the fields in input types can be other input types or scholars.
Arguments & Input Types DemoScott demonstrates how to code a type, an input type, how to query a type, and how to add arguments to a resolver.
Arguments & Input Types ExerciseStudents are instructed to create an input type, add arguments to queries, and use arguments in the query field resolvers to filter data. Scott answers questions from the audience about querying.
Arguments & Input Types SolutionScott live codes the solution to the arguments and input type exercise.
Mutation TypeScott explains that a mutation is a type on a schema that defines operations clients can perform to create, update, or delete data.
Mutation ExerciseStudents are instructed to define a mutation type in the schema, add fields to the mutation type, create input types or mutation field arguments and create resolvers for the mutation fields.
Mutation SolutionScott live codes the solution to the mutation exercise.
EnumsScott explains that enums are a set of discrete values that allow limiting a field to a few different options, and demonstrates how to add an enum to a type.
InterfacesScott explains that if there are two or more types with common fields, an interface allows types to share fields, and allows the client to make one query instead of multiple when looking for a field. An interface can resolve all the types that belongs to it.
Interfaces Q&AScott answers questions from the audience regarding interfaces and data sources, how to uncover the type of a type, and the GraphQL syntax.
UnionsScott explains that unions are similar to interfaces, because they give access to types. However, unlike interfaces, they can access types that have no fields in common with a single query. Questions from the audience are answered.
RelationshipsScott explains that in GraphQL, APIs are set of nodes linked to other nodes, and defines a relationship to be adding a type as a field value on another type.
Relationships DemoScott demonstrates how to use field level resolvers to write relationships between types.
Relationships ExerciseStudents are instructed to add new fields on types that reference other types and create resolvers for field types that point to other types.
Relationships Solution: Adding Fields on TypesScott live codes the first part of the solution to the relationships exercise by first adding new fields to different types.
Relationships Solution: Adding ResolversScott continues to live code the solution to the relationships exercise by adding field resolvers, and making the querying of data possible.
Relationships Q&AScott answers questions from the audience regarding queries in GraphQL, field level resolvers, and the rthe order queries run in.
AuthenticationScott demonstrates how to add authentication to an Apollo server, and explains that the level of authentication depends on what needs to be protected within the schema. Request level caching to avoid querying the database each time is also discussed.