microsoftgraph / msgraph-sdk-ruby

Microsoft Graph Ruby client library for v1 APIs
https://graph.microsoft.com
MIT License
100 stars 68 forks source link

uninitialized constant MicrosoftGraphCore::Authentication (NameError) #86

Closed Mohammed-Balfaqih closed 1 year ago

Mohammed-Balfaqih commented 1 year ago

I tried to install the gem and I went through the Create an AuthenticationProvider object

require "microsoft_kiota_authentication_oauth"
require "microsoft_graph_core"

context = MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new("<the tenant id from your app registration>", "<the client id from your app registration>", "<the client secret from your app registration>")

authentication_provider = MicrosoftGraphCore::Authentication::OAuthAuthenticationProvider.new(context, nil, ["Files.Read"])

I replaced the ids & secrets with my credentials, Then I got this error:

uninitialized constant MicrosoftGraphCore::Authentication (NameError)

I added to my gemfile: gem 'microsoft_graph'

Mohammed-Balfaqih commented 1 year ago

@baywet @ddyett any idea?

baywet commented 1 year ago

Hi @Mohammed-Balfaqih Thanks for reaching out and for your interest in the SDK. Please refrain from mentioning people who are not already on the thread, we have a thorough triage process and it'll create more noise and confusion than anything, potentially delaying the answer.

Can you try directly adding the microsoft_graph_core gem v 0.2.0 to your project and let us know whether this resolves the issue please?

Mohammed-Balfaqih commented 1 year ago

OK, Thanks @baywet for your I added gem 'microsoft_graph_core', '~> 0.2.0' and I got

Bundler could not find compatible versions for gem "microsoft_graph_core":
  In Gemfile:
    microsoft_graph_core (~> 0.2.0)

    microsoft_graph was resolved to 0.12.0, which depends on
      microsoft_graph_core (~> 0.1.0)
baywet commented 1 year ago

Can you upgrade microsoft_graph to 0.13.0 please?

rishi-jisr commented 1 year ago

@baywet We are using Ruby version 2.7.2 with rails 6 so it is not an easy to upgrade on Ruby 3

Mohammed-Balfaqih commented 1 year ago

@baywet @rishi-jisr I created a new rails project with Ruby 3.0.0 and installed these gems:

 gem 'microsoft_graph', '~> 0.13.0'
gem 'microsoft_graph_core', '~> 0.2.0'

and I got this issue:

/Users/balfaqih/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/microsoft_graph-0.13.0/lib/models/access_package_assignment_state.rb:1:in `<main>': uninitialized constant MicrosoftGraph (NameError)

My gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    actioncable (7.0.4.2)
      actionpack (= 7.0.4.2)
      activesupport (= 7.0.4.2)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
    actionmailbox (7.0.4.2)
      actionpack (= 7.0.4.2)
      activejob (= 7.0.4.2)
      activerecord (= 7.0.4.2)
      activestorage (= 7.0.4.2)
      activesupport (= 7.0.4.2)
      mail (>= 2.7.1)
      net-imap
      net-pop
      net-smtp
    actionmailer (7.0.4.2)
      actionpack (= 7.0.4.2)
      actionview (= 7.0.4.2)
      activejob (= 7.0.4.2)
      activesupport (= 7.0.4.2)
      mail (~> 2.5, >= 2.5.4)
      net-imap
      net-pop
      net-smtp
      rails-dom-testing (~> 2.0)
    actionpack (7.0.4.2)
      actionview (= 7.0.4.2)
      activesupport (= 7.0.4.2)
      rack (~> 2.0, >= 2.2.0)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.2.0)
    actiontext (7.0.4.2)
      actionpack (= 7.0.4.2)
      activerecord (= 7.0.4.2)
      activestorage (= 7.0.4.2)
      activesupport (= 7.0.4.2)
      globalid (>= 0.6.0)
      nokogiri (>= 1.8.5)
    actionview (7.0.4.2)
      activesupport (= 7.0.4.2)
      builder (~> 3.1)
      erubi (~> 1.4)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.1, >= 1.2.0)
    activejob (7.0.4.2)
      activesupport (= 7.0.4.2)
      globalid (>= 0.3.6)
    activemodel (7.0.4.2)
      activesupport (= 7.0.4.2)
    activerecord (7.0.4.2)
      activemodel (= 7.0.4.2)
      activesupport (= 7.0.4.2)
    activestorage (7.0.4.2)
      actionpack (= 7.0.4.2)
      activejob (= 7.0.4.2)
      activerecord (= 7.0.4.2)
      activesupport (= 7.0.4.2)
      marcel (~> 1.0)
      mini_mime (>= 1.1.0)
    activesupport (7.0.4.2)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 1.6, < 2)
      minitest (>= 5.1)
      tzinfo (~> 2.0)
    addressable (2.8.1)
      public_suffix (>= 2.0.2, < 6.0)
    bootsnap (1.16.0)
      msgpack (~> 1.2)
    builder (3.2.4)
    concurrent-ruby (1.2.0)
    crass (1.0.6)
    date (3.3.3)
    debug (1.7.1)
      irb (>= 1.5.0)
      reline (>= 0.3.1)
    erubi (1.12.0)
    faraday (2.7.4)
      faraday-net_http (>= 2.0, < 3.1)
      ruby2_keywords (>= 0.0.4)
    faraday-net_http (3.0.2)
    globalid (1.1.0)
      activesupport (>= 5.0)
    hashie (5.0.0)
    i18n (1.12.0)
      concurrent-ruby (~> 1.0)
    io-console (0.6.0)
    irb (1.6.2)
      reline (>= 0.3.0)
    iso8601 (0.13.0)
    json (2.6.3)
    jwt (2.7.0)
    loofah (2.19.1)
      crass (~> 1.0.2)
      nokogiri (>= 1.5.9)
    mail (2.8.1)
      mini_mime (>= 0.1.1)
      net-imap
      net-pop
      net-smtp
    marcel (1.0.2)
    method_source (1.0.0)
    microsoft_graph (0.13.0)
      microsoft_graph_core (>= 0.1, < 0.3)
    microsoft_graph_core (0.2.0)
      microsoft_kiota_abstractions (~> 0.13.0, >= 0.13.0)
      microsoft_kiota_authentication_oauth (>= 0.7, < 0.8)
      microsoft_kiota_faraday (>= 0.10, < 0.12)
      microsoft_kiota_serialization_json (~> 0.8.0)
    microsoft_kiota_abstractions (0.13.0)
      addressable (~> 2.7, >= 2.7.0)
      iso8601 (~> 0.13.0)
    microsoft_kiota_authentication_oauth (0.7.0)
      microsoft_kiota_abstractions (~> 0.13.0, >= 0.13.0)
      oauth2 (~> 2.0)
    microsoft_kiota_faraday (0.11.0)
      faraday (~> 2.7, >= 2.7.2)
      microsoft_kiota_abstractions (~> 0.13.0, >= 0.13.0)
    microsoft_kiota_serialization_json (0.8.0)
      json (~> 2.6.3)
      microsoft_kiota_abstractions (~> 0.13.0, >= 0.13.0)
      uuidtools (~> 2.2.0)
    mini_mime (1.1.2)
    minitest (5.17.0)
    msgpack (1.6.0)
    multi_xml (0.6.0)
    net-imap (0.3.4)
      date
      net-protocol
    net-pop (0.1.2)
      net-protocol
    net-protocol (0.2.1)
      timeout
    net-smtp (0.3.3)
      net-protocol
    nio4r (2.5.8)
    nokogiri (1.14.1-arm64-darwin)
      racc (~> 1.4)
    oauth2 (2.0.9)
      faraday (>= 0.17.3, < 3.0)
      jwt (>= 1.0, < 3.0)
      multi_xml (~> 0.5)
      rack (>= 1.2, < 4)
      snaky_hash (~> 2.0)
      version_gem (~> 1.1)
    public_suffix (5.0.1)
    puma (5.6.5)
      nio4r (~> 2.0)
    racc (1.6.2)
    rack (2.2.6.2)
    rack-test (2.0.2)
      rack (>= 1.3)
    rails (7.0.4.2)
      actioncable (= 7.0.4.2)
      actionmailbox (= 7.0.4.2)
      actionmailer (= 7.0.4.2)
      actionpack (= 7.0.4.2)
      actiontext (= 7.0.4.2)
      actionview (= 7.0.4.2)
      activejob (= 7.0.4.2)
      activemodel (= 7.0.4.2)
      activerecord (= 7.0.4.2)
      activestorage (= 7.0.4.2)
      activesupport (= 7.0.4.2)
      bundler (>= 1.15.0)
      railties (= 7.0.4.2)
    rails-dom-testing (2.0.3)
      activesupport (>= 4.2.0)
      nokogiri (>= 1.6)
    rails-html-sanitizer (1.5.0)
      loofah (~> 2.19, >= 2.19.1)
    railties (7.0.4.2)
      actionpack (= 7.0.4.2)
      activesupport (= 7.0.4.2)
      method_source
      rake (>= 12.2)
      thor (~> 1.0)
      zeitwerk (~> 2.5)
    rake (13.0.6)
    reline (0.3.2)
      io-console (~> 0.5)
    ruby2_keywords (0.0.5)
    snaky_hash (2.0.1)
      hashie
      version_gem (~> 1.1, >= 1.1.1)
    sqlite3 (1.6.0-arm64-darwin)
    thor (1.2.1)
    timeout (0.3.1)
    tzinfo (2.0.6)
      concurrent-ruby (~> 1.0)
    uuidtools (2.2.0)
    version_gem (1.1.1)
    websocket-driver (0.7.5)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.5)
    zeitwerk (2.6.6)

PLATFORMS
  arm64-darwin-21

DEPENDENCIES
  bootsnap
  debug
  microsoft_graph (~> 0.13.0)
  microsoft_graph_core (~> 0.2.0)
  puma (~> 5.0)
  rails (~> 7.0.4, >= 7.0.4.2)
  sqlite3 (~> 1.4)
  tzinfo-data

RUBY VERSION
   ruby 3.0.0p0

BUNDLED WITH
   2.2.3
baywet commented 1 year ago

@Mohammed-Balfaqih did you require "microsoft_graph" too?

@rishi-jisr since ruby 2.7 support is ending in April this year 4 years + 4 months and with our timelines, we're unlikely to invest in any work involving that version.

rishi-jisr commented 1 year ago

@baywet We are getting this error while rails c command

Mohammed-Balfaqih commented 1 year ago

@baywet I added require "microsoft_graph" into my application.rb and unfortunately the same error appears

baywet commented 1 year ago

Thanks for the additional information. It almost looks like requires are not processed in the right order. Could one of you share a small repro project please?

Mohammed-Balfaqih commented 1 year ago

Yes sure @baywet , you can check the last commit here

baywet commented 1 year ago

Thanks for sharing the repro with me. After doing some investigation it seems that rails loads things differently from plain ruby/rspec

After changing the way we declare modules from

module MicrosoftGraph::Models
    AccessPackageAssignmentState = {
        Delivering: :Delivering,
        PartiallyDelivered: :PartiallyDelivered,
        Delivered: :Delivered,
        Expired: :Expired,
        DeliveryFailed: :DeliveryFailed,
        UnknownFutureValue: :UnknownFutureValue,
    }
end

to

module MicrosoftGraph
    module Models
        AccessPackageAssignmentState = {
            Delivering: :Delivering,
            PartiallyDelivered: :PartiallyDelivered,
            Delivered: :Delivered,
            Expired: :Expired,
            DeliveryFailed: :DeliveryFailed,
            UnknownFutureValue: :UnknownFutureValue,
        }
    end
end

It seemed to work. This also probably means we don't need an empty module at the route (e.g. models.rb in models). And would probably solve our beta generation issue (right now beta is blocked because of a module resolution issue that looks similar).

I'm not sure what are the downsides of changing that declaration syntax both for plain ruby and for rails. If some of you could provide additional context here, it'd be helpful.

baywet commented 1 year ago

started a tentative fix over here https://github.com/microsoft/kiota/pull/2283

baywet commented 1 year ago

fixed with 0.15.0 (currently being released, should be up in a couple of minutes)