You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: create_external_profile.rb
    path of file: ./repos/chaskiq/app/graphql/mutations/app_users
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

module Mutations
  module AppUsers
    class CreateExternalProfile < Mutations::BaseMutation
      field :profile, Types::ExternalProfileType, null: false
      field :errors, Types::JsonType, null: false

      argu
    
      def resolve(app_key:, user_id:, provider:, profile_id:)
        app = current_user.apps.find_by(key: app_key)
        user = app.app_users.find(user_id)
        authorize! app, to: :can_manage_users?, with: AppPolicy, context: { app: app }

        profile = user.external_profiles.find_or_initialize_by(
          provider: provider,
          profile_id: profile_id
        )

        profile.save

        { profile: profile, errors: profile.errors }
      end