...

/

Implementing First Resolver

Implementing First Resolver

Learn how to define custom GraphQL types and implement simple query resolvers.

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.

Press + to interact
type Product {
name: String!,
description: String!,
url: String!,
numberOfVotes: Int!,
publishedAt: String!,
}

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.

Press + to interact
type Query {
appName: String
# New query to return a list of products
allProducts: [Product!]!
}

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 return type of ...