field(key, { as, alias, trim, transform, type } = {}) {
    const name = alias || key;
    let value = this.input[key];

    if (value && trim) {
      value = textTrim(value, trim === true ? undefined : trim);
    }

    if (value && transform) {
      value = transform(value);
    }

    if (value && type) {
      const globalId = fromGlobalId(value);

      if (globalId.type !== type) {
        throw new Error(
          `Expected an ID of type '${type}' but got '${globalId.type}'.`,
        );
      }

      value = globalId.id;
    }

    this.state = {
      key,
      as,
      name,
      value,
      promise: undefined,
      addError: message =>
        this.errors.push({
          key,
          message: message || `The ${name} field is invalid.`,
        }),
    };
    this.states.push(this.state);
    return this;
  }
Initialized a new state for the field.