Input object type as an argument for GraphQL mutations and queries

David Mráz
Atheros
Published in
6 min readAug 14, 2017

--

(This article is also available at atheros.ai without the paywall.)

Introduction

In the previous articles, we talked about the basic set-up for GraphQL projects as well as the use of GraphiQL for executing queries and mutations. With this knowledge, we can now dive deeper into the world of GraphQL input types. GraphQL is a query language, which can be used with different languages like Javascript, C#, Scala, and more. However, in this article, we will focus on Facebook’s Javascript implementation of GraphQL called graphql-js. We will also introduce some code snippets and examples illustrating how different types can be written in the GraphQL schema language. This is not language-specific, however, and the main focus will be on designing a GraphQL schema using the graphql-js classes. We will concentrate on the often misunderstood topic of using GraphQL input object types in mutations.

Input and output types

According to GraphQL specification, when we deal with its type system, we have to discuss two different categories of types:

  • output type can be used for the definition of data, which is obtained after query execution;
  • input types are used as query parameters, e.g., the payload for…

--

--

David Mráz
Atheros

Founder of https://atheros.ai | Artificial Intelligence | Machine Learning | JavaScript, Python, C++ | Business