Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

GraphQL · Class

GraphQLObjectType

GraphQLObjectType defines a schema object with named, selectable fields. Each field has an output type and can accept input arguments and resolve its value.

How it works

GraphQLObjectType is the JavaScript constructor used to define a concrete GraphQL object in a schema. Its configuration names the type and supplies fields; each field declares an output type and may provide a resolver that produces the field value.

Syntax

new GraphQLObjectType({ name, fields })

Parameters

NameTypeDescription
configGraphQLObjectTypeConfigConfiguration object containing the type name and field definitions; individual fields specify output types and may define arguments and resolvers.

Returns

A GraphQL object type representing a fetchable kind of object and its fields.

Key points

  • Object types are the primary schema building blocks for describing fetchable entities.
  • Each object type describes a concrete kind of data that a client can request.
  • The type's fields define the named pieces of data available for selection.
  • Object is one of GraphQL's six named type categories, alongside scalar, enum, interface, union, and input object.
  • Every object field declares the kind of output value it returns, including wrapped forms such as lists or non-null values.

Common mistakes

  • Object fields are outputs: their declared types must be output types, not input-only types.
  • Field arguments are inputs, so argument definitions must use input types even though the field result is an output type.
  • A schema's query root must be an object type; a scalar, input object, or other non-object type cannot serve as the query root.

Example: A minimal object type

import { graphql, GraphQLObjectType, GraphQLSchema, GraphQLString } from "graphql";

const Query = new GraphQLObjectType({
  name: "Query",
  fields: {
    greeting: {
      type: GraphQLString,
      resolve: () => "Hello, GraphQL!",
    },
  },
});

const schema = new GraphQLSchema({ query: Query });

const result = await graphql({
  schema,
  source: "{ greeting }",
});

console.log(result.data?.greeting);

Defines an object type with one output field, uses it as the query root, and executes a matching query.

When to use it

Model fetchable entities

Define an entity such as User, Product, or Order with fields clients can select.

Create a query root

Expose the entry points for read operations through a Query object.

Resolve application data

Connect schema fields to application data sources with resolver functions.

Interview questions

QWhat does GraphQLObjectType represent?

GraphQLObjectType defines an object type in the executable schema. The type groups named fields, and each field exposes an output type; fields can also accept arguments and resolve values.

Follow-up: How would you model a field that accepts a filter? Define the field's return type as an output type and define its arguments with input types, such as scalars or input objects.

QHow do object types shape a GraphQL query?

An object type represents a kind of object that clients can fetch and the fields available on it. Its fields describe the selectable data and their relationships to other types.

Follow-up: Why can objects form nested query trees? Because an object field can return another object, allowing clients to select fields at successive levels.

QWhat requirement applies to the query root?

The query root must be an object type. It is the starting point for query operations, and its fields expose the operations clients may select.

Follow-up: Can the query root be an input object? No. Input objects are for arguments; the query root must be an output object type.

  • GraphQLSchema
  • Scalar types
  • Enum types
  • Interface types
  • Union types
  • Input Object types

Source: Schemas and Types. Checked 2026-10-15.