<commit_before>module Types
  EnrollmentType = GraphQL::ObjectType.define do
    name "Enrollment"

    implements GraphQL::Relay::Node.interface
    global_id_field :id
    field :_id, !types.ID, "legacy canvas id", property: :id

    field :user, UserType do
      resolve ->(enrollment, _, ctx) {
        Loaders::IDLoader.for(User).load(enrollment.user_id)
      }
    end
    field :course, CourseType do
      resolve ->(enrollment, _, _) {
        Loaders::IDLoader.for(Course).load(enrollment.course_id)
      }
    end
    field :section, SectionType do
      resolve ->(enrollment, _, _) {
        Loaders::IDLoader.for(CourseSection).load(enrollment.course_section_id)
      }
    end

    field :state, !EnrollmentWorkflowState, property: :workflow_state

    field :type, !EnrollmentTypeType

    field :grades, GradesType do
      argument :gradingPeriodId, types.ID,
        "The grading period to return grades for. If not specified, will use the current grading period (or the course grade for courses that don't use grading periods)",
        prepare: GraphQLHelpers.relay_or_legacy_id_prepare_func("GradingPeriod")

      resolve ->(enrollment, args, ctx) {
        grades_resolver = ->(grading_period_id) do
          grading_period_id = grading_period_id.to_i if grading_period_id
          grades = enrollment.find_score(grading_period_id: grading_period_id)
          grades && grades.grants_right?(ctx[:current_user], :read) ?
            grades :
            nil
        end

        Loaders::AssociationLoader.for(Enrollment, [:scores, :user, :course])
          .load(enrollment).then do
            if grading_period_id = args[:gradingPeriodId]
              grades_resolver.call(grading_period_id)
            else
              CourseGradingPeriodLoader.load(enrollment.course).then { |gp|
                grades_resolver.call(gp&.id)
              }
            end
          end
      }
    end
  end

  EnrollmentWorkflowState = GraphQL::EnumType.define do
    name "EnrollmentWorkflowState"
    value "invited"
    value "creation_pending"
    value "active"
    value "deleted"
    value "rejected"
    value "completed"
  end

  EnrollmentTypeType = GraphQL::EnumType.define do
    name "EnrollmentType"
    value "StudentEnrollment"
    value "TeacherEnrollment"
    value "TaEnrollment"
    value "ObserverEnrollment"
    value "DesignerEnrollment"
    value "StudentViewEnrollment"
  end
end
<commit_msg>graphql: add lastActivityAt to enrollment type<commit_after>module Types
  EnrollmentType = GraphQL::ObjectType.define do
    name "Enrollment"

    implements GraphQL::Relay::Node.interface
    global_id_field :id
    field :_id, !types.ID, "legacy canvas id", property: :id

    field :user, UserType do
      resolve ->(enrollment, _, ctx) {
        Loaders::IDLoader.for(User).load(enrollment.user_id)
      }
    end
    field :course, CourseType do
      resolve ->(enrollment, _, _) {
        Loaders::IDLoader.for(Course).load(enrollment.course_id)
      }
    end
    field :section, SectionType do
      resolve ->(enrollment, _, _) {
        Loaders::IDLoader.for(CourseSection).load(enrollment.course_section_id)
      }
    end

    field :state, !EnrollmentWorkflowState, property: :workflow_state

    field :type, !EnrollmentTypeType

    field :grades, GradesType do
      argument :gradingPeriodId, types.ID,
        "The grading period to return grades for. If not specified, will use the current grading period (or the course grade for courses that don't use grading periods)",
        prepare: GraphQLHelpers.relay_or_legacy_id_prepare_func("GradingPeriod")

      resolve ->(enrollment, args, ctx) {
        grades_resolver = ->(grading_period_id) do
          grading_period_id = grading_period_id.to_i if grading_period_id
          grades = enrollment.find_score(grading_period_id: grading_period_id)
          grades && grades.grants_right?(ctx[:current_user], :read) ?
            grades :
            nil
        end

        Loaders::AssociationLoader.for(Enrollment, [:scores, :user, :course])
          .load(enrollment).then do
            if grading_period_id = args[:gradingPeriodId]
              grades_resolver.call(grading_period_id)
            else
              CourseGradingPeriodLoader.load(enrollment.course).then { |gp|
                grades_resolver.call(gp&.id)
              }
            end
          end
      }
    end

    field :lastActivityAt, TimeType, property: :last_activity_at
  end

  EnrollmentWorkflowState = GraphQL::EnumType.define do
    name "EnrollmentWorkflowState"
    value "invited"
    value "creation_pending"
    value "active"
    value "deleted"
    value "rejected"
    value "completed"
  end

  EnrollmentTypeType = GraphQL::EnumType.define do
    name "EnrollmentType"
    value "StudentEnrollment"
    value "TeacherEnrollment"
    value "TaEnrollment"
    value "ObserverEnrollment"
    value "DesignerEnrollment"
    value "StudentViewEnrollment"
  end
end

{'fraction_non_alphanumeric': 0.08866599799398195, 'fraction_numerical': 0.0, 'mean_word_length': 2.8412942989214174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5378187', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1510, 'n_words': 336}