Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/drash/src/services/graphql/graphql.ts>GraphQL.GraphQLObjectType

A microframework for Deno's HTTP server with zero third-party dependencies
Go to Latest
class GraphQL.GraphQLObjectType
import { GraphQL } from "https://deno.land/x/drash@v2.8.1/src/services/graphql/graphql.ts";
const { GraphQLObjectType } = GraphQL;

Object Type Definition

Almost all of the GraphQL types you define will be object types. Object types have a name, but most importantly describe their fields.

Example:

const AddressType = new GraphQLObjectType({
  name: 'Address',
  fields: {
    street: { type: GraphQLString },
    number: { type: GraphQLInt },
    formatted: {
      type: GraphQLString,
      resolve(obj) {
        return obj.number + ' ' + obj.street
      }
    }
  }
});

When two types need to refer to each other, or a type needs to refer to itself in a field, you can use a function expression (aka a closure or a thunk) to supply the fields lazily.

Example:

const PersonType = new GraphQLObjectType({
  name: 'Person',
  fields: () => ({
    name: { type: GraphQLString },
    bestFriend: { type: PersonType },
  })
});

Constructors

new
GraphQLObjectType(config: Readonly<GraphQLObjectTypeConfig<TSource, TContext>>)

Type Parameters

optional
TSource = any
optional
TContext = any

Properties

astNode: Maybe<ObjectTypeDefinitionNode>
description: Maybe<string>
extensionASTNodes: Maybe<ReadonlyArray<ObjectTypeExtensionNode>>
extensions: Maybe<Readonly<GraphQLObjectTypeExtensions<TSource, TContext>>>
name: string

Methods

inspect(): string
toConfig(): GraphQLObjectTypeConfig<any, any> & { interfaces: Array<GraphQLInterfaceType>; fields: GraphQLFieldConfigMap<any, any>; extensions: Maybe<Readonly<GraphQLObjectTypeExtensions<TSource, TContext>>>; extensionASTNodes: ReadonlyArray<ObjectTypeExtensionNode>; }
toJSON(): string
toString(): string