Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

GraphQLObjectType

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 },
  })
});
class GraphQLObjectType<TSource = any, TContext = any> {
constructor(config: Readonly<GraphQLObjectTypeConfig<TSource, TContext>>);
private _fields;
private _interfaces;
astNode: Maybe<ObjectTypeDefinitionNode>;
description: Maybe<string>;
extensionASTNodes: ReadonlyArray<ObjectTypeExtensionNode>;
extensions: Readonly<GraphQLObjectTypeExtensions<TSource, TContext>>;
isTypeOf: Maybe<GraphQLIsTypeOfFn<TSource, TContext>>;
name: string;
get [Symbol.toStringTag](): string;
 
getFields(): GraphQLFieldMap<TSource, TContext>;
getInterfaces(): ReadonlyArray<GraphQLInterfaceType>;
toConfig(): GraphQLObjectTypeNormalizedConfig<TSource, TContext>;
toJSON(): string;
toString(): string;
}

§Type Parameters

§
TSource = any
[src]
§
TContext = any
[src]

§Constructors

§
new GraphQLObjectType(config: Readonly<GraphQLObjectTypeConfig<TSource, TContext>>)
[src]

§Properties

§
_fields
[src]
§
_interfaces
[src]
§
description: Maybe<string>
[src]
§
extensionASTNodes: ReadonlyArray<ObjectTypeExtensionNode>
[src]
§
extensions: Readonly<GraphQLObjectTypeExtensions<TSource, TContext>>
[src]
§
isTypeOf: Maybe<GraphQLIsTypeOfFn<TSource, TContext>>
[src]
§
name: string
[src]
§
[Symbol.toStringTag]: string readonly
[src]

§Methods

§
getFields(): GraphQLFieldMap<TSource, TContext>
[src]
§
getInterfaces(): ReadonlyArray<GraphQLInterfaceType>
[src]
§
toConfig(): GraphQLObjectTypeNormalizedConfig<TSource, TContext>
[src]
§
toJSON(): string
[src]
§
toString(): string
[src]