Implementing First Resolver
Explore how to define a Product type schema and implement a resolver to fetch product data in memory. Understand GraphQL's strict type enforcement, error responses for null or incorrect data, and how the server guarantees data shape compliance compared to REST APIs.
We'll cover the following...
GraphQL schema
First, let’s define a GraphQL schema for the Product type. This type will represent products that users share on our website and will contain some basic types, such as a name, a description, and a URL for the product.
As mentioned in an earlier lesson, this definition shouldn’t look very cryptic. It says that each product will contain five fields and they will either be a String or Int type. Notice that all types are prepended with the ! symbol, which means that the return values will be non-null.
In addition to defining a new type, we also need to define a new query that will return a list of products.
There are a few things to notice in this response. First, the allProducts query won’t receive any parameters. For now, it’ll return all the products available on our server. This is temporary, and we’ll take care of the pagination later.
Second, the way the ...