Skip to content

Object types must have fields (FieldsAreRequiredError) #283

@alice-sugarblock

Description

@alice-sugarblock

Describe the bug

The graphql-ruby library introduced a change in 2.4.5 (2 Dec 2024) that issues a warning whenever a schema object is created without fields (see rmosolgo/graphql-ruby#5137).

While we were upgrading our dependencies, this message started popping up in our tests and we found the source to be within the default QueryType and MutationType definitions of this library.

The solution would be to declare explicitly that these objects do not have any fields:

module GraphqlDevise
  module Types
    class QueryType < GraphQL::Schema::Object
      # Silence "Object types must have fields" warning
      has_no_fields(true)

      field_class GraphqlDevise::Types::BaseField if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('2.0')
    end
  end
end
module GraphqlDevise
  module Types
    class MutationType < GraphQL::Schema::Object
      # Silence "Object types must have fields" warning
      has_no_fields(true)

      field_class GraphqlDevise::Types::BaseField if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('2.0')
    end
  end
end

But in an attempt to solve it in the meantime, we're calling the method within our Rails environment initializer:

# Load the Rails application.
require_relative 'application'

# Silence "Object types must have fields" warning
GraphqlDevise::Types::QueryType.has_no_fields(true)
GraphqlDevise::Types::MutationType.has_no_fields(true)

# Initialize the Rails application.
Rails.application.initialize!

We're not sure if this is the proper solution tho :/

Environment

Gemfile.lock

GIT
  remote: https://github.com/GemHQ/money-tree
  revision: 36fc4bece3e8ad39befe446af0a9d58dd3ebfa4b
  specs:
    money-tree (0.11.2)
      bech32 (~> 1.2)
      openssl (~> 3.0)

GEM
  remote: https://rubygems.org/
  specs:
    Ascii85 (2.0.1)
    aasm (5.4.0)
      concurrent-ruby (~> 1.0)
    actioncable (6.1.7.10)
      actionpack (= 6.1.7.10)
      activesupport (= 6.1.7.10)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
    actionmailbox (6.1.7.10)
      actionpack (= 6.1.7.10)
      activejob (= 6.1.7.10)
      activerecord (= 6.1.7.10)
      activestorage (= 6.1.7.10)
      activesupport (= 6.1.7.10)
      mail (>= 2.7.1)
    actionmailer (6.1.7.10)
      actionpack (= 6.1.7.10)
      actionview (= 6.1.7.10)
      activejob (= 6.1.7.10)
      activesupport (= 6.1.7.10)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 2.0)
    actionpack (6.1.7.10)
      actionview (= 6.1.7.10)
      activesupport (= 6.1.7.10)
      rack (~> 2.0, >= 2.0.9)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.2.0)
    actiontext (6.1.7.10)
      actionpack (= 6.1.7.10)
      activerecord (= 6.1.7.10)
      activestorage (= 6.1.7.10)
      activesupport (= 6.1.7.10)
      nokogiri (>= 1.8.5)
    actionview (6.1.7.10)
      activesupport (= 6.1.7.10)
      builder (~> 3.1)
      erubi (~> 1.4)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.1, >= 1.2.0)
    activejob (6.1.7.10)
      activesupport (= 6.1.7.10)
      globalid (>= 0.3.6)
    activemodel (6.1.7.10)
      activesupport (= 6.1.7.10)
    activerecord (6.1.7.10)
      activemodel (= 6.1.7.10)
      activesupport (= 6.1.7.10)
    activestorage (6.1.7.10)
      actionpack (= 6.1.7.10)
      activejob (= 6.1.7.10)
      activerecord (= 6.1.7.10)
      activesupport (= 6.1.7.10)
      marcel (~> 1.0)
      mini_mime (>= 1.1.0)
    activesupport (6.1.7.10)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 1.6, < 2)
      minitest (>= 5.1)
      tzinfo (~> 2.0)
      zeitwerk (~> 2.3)
    addressable (2.8.7)
      public_suffix (>= 2.0.2, < 7.0)
    afm (0.2.2)
    after_commit_everywhere (1.3.0)
      activerecord (>= 4.2)
      activesupport
    amazing_print (1.6.0)
    arask (1.2.5)
      fugit (~> 1.1)
      rails (>= 5.0)
    ast (2.4.2)
    attr_encrypted (3.1.0)
      encryptor (~> 3.0.0)
    aws-eventstream (1.2.0)
    aws-partitions (1.675.0)
    aws-sdk-core (3.168.4)
      aws-eventstream (~> 1, >= 1.0.2)
      aws-partitions (~> 1, >= 1.651.0)
      aws-sigv4 (~> 1.5)
      jmespath (~> 1, >= 1.6.1)
    aws-sdk-kms (1.61.0)
      aws-sdk-core (~> 3, >= 3.165.0)
      aws-sigv4 (~> 1.1)
    aws-sdk-lambda (1.88.0)
      aws-sdk-core (~> 3, >= 3.165.0)
      aws-sigv4 (~> 1.1)
    aws-sdk-rekognition (1.79.0)
      aws-sdk-core (~> 3, >= 3.165.0)
      aws-sigv4 (~> 1.1)
    aws-sdk-s3 (1.117.2)
      aws-sdk-core (~> 3, >= 3.165.0)
      aws-sdk-kms (~> 1)
      aws-sigv4 (~> 1.4)
    aws-sigv4 (1.5.2)
      aws-eventstream (~> 1, >= 1.0.2)
    base58 (0.2.3)
    base64 (0.2.0)
    bcrypt (3.1.20)
    bech32 (1.3.0)
      thor (>= 1.1.0)
    bigdecimal (3.1.9)
    bootsnap (1.15.0)
      msgpack (~> 1.2)
    builder (3.3.0)
    byebug (11.1.3)
    childprocess (5.1.0)
      logger (~> 1.5)
    choice (0.2.0)
    coderay (1.1.3)
    concurrent-ruby (1.3.4)
    contentful (2.17.1)
      http (> 0.8, < 6.0)
      multi_json (~> 1)
    countries (5.4.0)
      unaccent (~> 0.3)
    crack (0.4.5)
      rexml
    crass (1.0.6)
    date (3.4.1)
    declarative (0.0.20)
    delayed_job (4.1.11)
      activesupport (>= 3.0, < 8.0)
    delayed_job_active_record (4.1.8)
      activerecord (>= 3.0, < 8.0)
      delayed_job (>= 3.0, < 5)
    devise (4.9.4)
      bcrypt (~> 3.0)
      orm_adapter (~> 0.1)
      railties (>= 4.1.0)
      responders
      warden (~> 1.2.3)
    devise-two-factor (4.0.2)
      activesupport (< 7.1)
      attr_encrypted (>= 1.3, < 4, != 2)
      devise (~> 4.0)
      railties (< 7.1)
      rotp (~> 6.0)
    devise_token_auth (1.2.4)
      bcrypt (~> 3.0)
      devise (> 3.5.2, < 5)
      rails (>= 4.2.0, < 7.3)
    diff-lcs (1.5.0)
    domain_name (0.6.20240107)
    dotenv (3.1.4)
    dotenv-rails (3.1.4)
      dotenv (= 3.1.4)
      railties (>= 6.1)
    encryptor (3.0.0)
    erubi (1.13.1)
    et-orbi (1.2.11)
      tzinfo
    eventmachine (1.2.7)
    factory_bot (6.5.0)
      activesupport (>= 5.0.0)
    factory_bot_rails (6.4.4)
      factory_bot (~> 6.5)
      railties (>= 5.0.0)
    faraday (2.9.0)
      faraday-net_http (>= 2.0, < 3.2)
    faraday-net_http (3.1.0)
      net-http
    faye-websocket (0.11.3)
      eventmachine (>= 0.12.0)
      websocket-driver (>= 0.5.1)
    ffi (1.17.0-arm64-darwin)
    ffi (1.17.0-x86_64-darwin)
    ffi (1.17.0-x86_64-linux-gnu)
    ffi-compiler (1.3.2)
      ffi (>= 1.15.5)
      rake
    fiber-storage (1.0.0)
    fugit (1.11.1)
      et-orbi (~> 1, >= 1.2.11)
      raabro (~> 1.4)
    globalid (1.2.1)
      activesupport (>= 6.1)
    google-apis-core (0.14.0)
      addressable (~> 2.5, >= 2.5.1)
      googleauth (~> 1.9)
      httpclient (>= 2.8.1, < 3.a)
      mini_mime (~> 1.0)
      representable (~> 3.0)
      retriable (>= 2.0, < 4.a)
      rexml
    google-apis-sheets_v4 (0.28.0)
      google-apis-core (>= 0.14.0, < 2.a)
    google-cloud-env (2.1.1)
      faraday (>= 1.0, < 3.a)
    googleauth (1.11.0)
      faraday (>= 1.0, < 3.a)
      google-cloud-env (~> 2.1)
      jwt (>= 1.4, < 3.0)
      multi_json (~> 1.11)
      os (>= 0.9, < 2.0)
      signet (>= 0.16, < 2.a)
    graphql (2.4.8)
      base64
      fiber-storage
    graphql_devise (2.0.0)
      devise_token_auth (>= 0.1.43, < 2.0)
      graphql (>= 1.8, < 2.5)
      rails (>= 6.0, < 7.3)
      zeitwerk
    hashdiff (1.0.1)
    hashery (2.1.2)
    holidays (8.8.0)
    http (5.2.0)
      addressable (~> 2.8)
      base64 (~> 0.1)
      http-cookie (~> 1.0)
      http-form_data (~> 2.2)
      llhttp-ffi (~> 0.5.0)
    http-cookie (1.0.7)
      domain_name (~> 0.5)
    http-form_data (2.3.0)
    httparty (0.21.0)
      mini_mime (>= 1.0.0)
      multi_xml (>= 0.5.2)
    httpclient (2.8.3)
    i18n (1.14.7)
      concurrent-ruby (~> 1.0)
    jmespath (1.6.2)
    json (2.6.3)
    jwt (2.8.1)
      base64
    keccak256 (2.0.1)
    launchy (3.0.1)
      addressable (~> 2.8)
      childprocess (~> 5.0)
    letter_opener (1.10.0)
      launchy (>= 2.2, < 4)
    listen (3.7.1)
      rb-fsevent (~> 0.10, >= 0.10.3)
      rb-inotify (~> 0.9, >= 0.9.10)
    llhttp-ffi (0.5.0)
      ffi-compiler (~> 1.0)
      rake (~> 13.0)
    logger (1.6.1)
    loofah (2.24.0)
      crass (~> 1.0.2)
      nokogiri (>= 1.12.0)
    mail (2.8.1)
      mini_mime (>= 0.1.1)
      net-imap
      net-pop
      net-smtp
    marcel (1.0.4)
    matrix (0.4.2)
    method_source (1.1.0)
    mini_mime (1.1.5)
    minitest (5.25.4)
    msgpack (1.6.0)
    multi_json (1.15.0)
    multi_xml (0.6.0)
    net-http (0.3.2)
      uri
    net-imap (0.5.5)
      date
      net-protocol
    net-pop (0.1.2)
      net-protocol
    net-protocol (0.2.2)
      timeout
    net-smtp (0.5.0)
      net-protocol
    nio4r (2.7.4)
    nokogiri (1.18.2-arm64-darwin)
      racc (~> 1.4)
    nokogiri (1.18.2-x86_64-darwin)
      racc (~> 1.4)
    nokogiri (1.18.2-x86_64-linux-gnu)
      racc (~> 1.4)
    openssl (3.0.1)
    orm_adapter (0.5.0)
    os (1.1.4)
    parallel (1.22.1)
    parser (3.1.3.0)
      ast (~> 2.4.1)
    pdf-core (0.10.0)
    pdf-reader (2.13.0)
      Ascii85 (>= 1.0, < 3.0, != 2.0.0)
      afm (~> 0.2.1)
      hashery (~> 2.0)
      ruby-rc4
      ttfunk
    pg (1.4.5)
    phonelib (0.8.4)
    prawn (2.5.0)
      matrix (~> 0.4)
      pdf-core (~> 0.10.0)
      ttfunk (~> 1.8)
    prawn-table (0.2.2)
      prawn (>= 1.3.0, < 3.0.0)
    pry (0.14.1)
      coderay (~> 1.1)
      method_source (~> 1.0)
    public_suffix (6.0.1)
    puma (5.6.9)
      nio4r (~> 2.0)
    raabro (1.4.0)
    racc (1.8.1)
    rack (2.2.10)
    rack-cors (1.1.1)
      rack (>= 2.0.0)
    rack-test (2.2.0)
      rack (>= 1.3)
    rails (6.1.7.10)
      actioncable (= 6.1.7.10)
      actionmailbox (= 6.1.7.10)
      actionmailer (= 6.1.7.10)
      actionpack (= 6.1.7.10)
      actiontext (= 6.1.7.10)
      actionview (= 6.1.7.10)
      activejob (= 6.1.7.10)
      activemodel (= 6.1.7.10)
      activerecord (= 6.1.7.10)
      activestorage (= 6.1.7.10)
      activesupport (= 6.1.7.10)
      bundler (>= 1.15.0)
      railties (= 6.1.7.10)
      sprockets-rails (>= 2.0.0)
    rails-dom-testing (2.2.0)
      activesupport (>= 5.0.0)
      minitest
      nokogiri (>= 1.6)
    rails-erd (1.7.2)
      activerecord (>= 4.2)
      activesupport (>= 4.2)
      choice (~> 0.2.0)
      ruby-graphviz (~> 1.2)
    rails-html-sanitizer (1.6.2)
      loofah (~> 2.21)
      nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
    rails_semantic_logger (4.14.0)
      rack
      railties (>= 5.1)
      semantic_logger (~> 4.13)
    railties (6.1.7.10)
      actionpack (= 6.1.7.10)
      activesupport (= 6.1.7.10)
      method_source
      rake (>= 12.2)
      thor (~> 1.0)
    rainbow (3.1.1)
    rake (13.2.1)
    rb-fsevent (0.11.2)
    rb-inotify (0.10.1)
      ffi (~> 1.0)
    regexp_parser (2.6.1)
    representable (3.2.0)
      declarative (< 0.1.0)
      trailblazer-option (>= 0.1.1, < 0.2.0)
      uber (< 0.2.0)
    responders (3.1.1)
      actionpack (>= 5.2)
      railties (>= 5.2)
    retriable (3.1.2)
    rexml (3.3.9)
    rich_text_renderer (0.3.0)
    rotp (6.3.0)
    rspec-core (3.12.0)
      rspec-support (~> 3.12.0)
    rspec-expectations (3.12.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.12.0)
    rspec-mocks (3.12.1)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.12.0)
    rspec-rails (5.0.3)
      actionpack (>= 5.2)
      activesupport (>= 5.2)
      railties (>= 5.2)
      rspec-core (~> 3.10)
      rspec-expectations (~> 3.10)
      rspec-mocks (~> 3.10)
      rspec-support (~> 3.10)
    rspec-support (3.12.0)
    rubocop (1.39.0)
      json (~> 2.3)
      parallel (~> 1.10)
      parser (>= 3.1.2.1)
      rainbow (>= 2.2.2, < 4.0)
      regexp_parser (>= 1.8, < 3.0)
      rexml (>= 3.2.5, < 4.0)
      rubocop-ast (>= 1.23.0, < 2.0)
      ruby-progressbar (~> 1.7)
      unicode-display_width (>= 1.4.0, < 3.0)
    rubocop-ast (1.24.0)
      parser (>= 3.1.1.0)
    rubocop-graphql (1.2.0)
      rubocop (>= 0.87, < 2)
    rubocop-rails (2.17.3)
      activesupport (>= 4.2.0)
      rack (>= 1.1)
      rubocop (>= 1.33.0, < 2.0)
    rubocop-rspec (2.16.0)
      rubocop (~> 1.33)
    ruby-graphviz (1.2.5)
      rexml
    ruby-progressbar (1.11.0)
    ruby-rc4 (0.1.5)
    rubyzip (2.3.2)
    semantic_logger (4.15.0)
      concurrent-ruby (~> 1.0)
    shoulda-matchers (5.2.0)
      activesupport (>= 5.2.0)
    signet (0.19.0)
      addressable (~> 2.8)
      faraday (>= 0.17.5, < 3.a)
      jwt (>= 1.5, < 3.0)
      multi_json (~> 1.10)
    slack-notifier (2.4.0)
    spring (4.1.0)
    sprockets (4.2.1)
      concurrent-ruby (~> 1.0)
      rack (>= 2.2.4, < 4)
    sprockets-rails (3.5.2)
      actionpack (>= 6.1)
      activesupport (>= 6.1)
      sprockets (>= 3.0.0)
    streamio-ffmpeg (3.0.2)
      multi_json (~> 1.8)
    tempfile (0.1.3)
    thor (1.3.2)
    timecop (0.9.6)
    timeout (0.4.3)
    trailblazer-option (0.1.2)
    ttfunk (1.8.0)
      bigdecimal (~> 3.1)
    tzinfo (2.0.6)
      concurrent-ruby (~> 1.0)
    uber (0.1.0)
    unaccent (0.4.0)
    unicode-display_width (2.3.0)
    uri (0.13.0)
    vcr (6.1.0)
    warden (1.2.9)
      rack (>= 2.0.9)
    webmock (3.18.1)
      addressable (>= 2.8.0)
      crack (>= 0.3.2)
      hashdiff (>= 0.4.0, < 2.0.0)
    websocket-driver (0.7.7)
      base64
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.5)
    zeitwerk (2.7.1)

PLATFORMS
  arm64-darwin-23
  x86_64-darwin-19
  x86_64-darwin-21
  x86_64-darwin-22
  x86_64-linux

DEPENDENCIES
  aasm
  after_commit_everywhere (~> 1.0)
  amazing_print
  arask
  aws-sdk-lambda (~> 1)
  aws-sdk-rekognition
  aws-sdk-s3 (~> 1)
  base58
  bootsnap (>= 1.4.4)
  byebug
  concurrent-ruby (= 1.3.4)
  contentful
  countries
  delayed_job_active_record
  devise-two-factor
  devise_token_auth (= 1.2.4)
  dotenv-rails
  factory_bot_rails
  faye-websocket
  google-apis-sheets_v4 (~> 0.28.0)
  googleauth
  graphql_devise
  holidays
  httparty
  keccak256
  letter_opener
  listen (~> 3.3)
  money-tree (~> 0.11.1)!
  pdf-reader
  pg (~> 1.1)
  phonelib
  prawn
  prawn-table
  pry (~> 0.14.1)
  puma (~> 5.6)
  rack-cors
  rails (~> 6.1.7)
  rails-erd
  rails_semantic_logger
  rich_text_renderer
  rspec-rails (~> 5.0.0)
  rubocop-graphql
  rubocop-rails
  rubocop-rspec
  rubyzip
  shoulda-matchers (~> 5.0)
  slack-notifier
  spring
  streamio-ffmpeg
  tempfile
  timecop
  tzinfo-data
  vcr
  webmock

RUBY VERSION
   ruby 3.2.2p53

BUNDLED WITH
   2.4.20

Steps to reproduce

This warning message appears whenever you use Rails:

$ bin/rails c
Object types must have fields, but Query doesn't have any. Define a field for this type, remove it from your schema, or add `has_no_fields(true)` to its definition.

This will raise an error in a future GraphQL-Ruby version.
Object types must have fields, but Mutation doesn't have any. Define a field for this type, remove it from your schema, or add `has_no_fields(true)` to its definition.

This will raise an error in a future GraphQL-Ruby version.
Running via Spring preloader in process 23697
Loading development environment (Rails 6.1.7.10)
irb(main):001:0> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions