Objects


So far we have only dealt with neutral and self-contained types. However, the true power of GraphQL comes from how it lets us compose simpler types to create more complex types. Let's begin with our first output type factory: t.object:

// Copying the Membership example from above for convenience
const Membership = t.enum({
  name: 'Membership',
  values: {
    free: null,
    paid: null,
    enterprise: null,
  },
});

const User = t.object({
  name: 'User',
  fields: {
    id: t.id,
    email: t.string.nullable,
    membership: Membership,
  },
});
/** TypeScript */

type User = {
  id: string | number;
  email: string | undefined | null;
  membership: 'free' | 'paid' | 'enterprise';
};
# GraphQL

type User {
  id: ID!
  email: String
  membership: Membership!
}
Edit on GitHub