rmosolgo / rmosolgo/graphql-ruby

Lookahead's `selects?` returns false for a field that is visible in `#selections` on a Union type

Open
#4,388 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
5.4k
Forks
1.4k
Avg merge
23h 19m
Merged PRs (30d)
28

Description

Describe the bug

Inside my resolver, whenever I call .selects?(:attachment), it returns false. Although the :attachment field is present whenever I do lookahead.selections.map(&:name) I find that the :attachment field is present

Versions

graphql: 1.13.15
rails: 6.0.3

GraphQL schema

# Types
class SavedReplyFolderType < ::Types::BaseObject
  # fields that are not :attachment
end

class SavedReplyType < ::Types::BaseObject
  # other fields
  field :attachment, ::Types::AttachmentType, null: true
end

class SavedReplyLeafUnion < ::Types::BaseUnion
  possible_types Types::SavedReplyType, Types::SavedReplyFolderType

  def self.resolve_type(object, context)
    if object.is_a?(::SavedReply)
      Types::SavedReplyType
    elsif object.is_a?(::SavedReplyFolder)
      Types::SavedReplyFolderType
    end
  end
end


# Resolvers
# Resolver for [SavedReplyLeafUnion]
module Resolvers
  class SavedRepliesTreeResolver < BaseResolver
    extras [:lookahead]
    def resolve(lookahead:)
       # try accessing lookahead here
    end
  end
end

GraphQL query

query savedRepliesTree {
  app {
    savedRepliesTree {
      __typename
      ... on SavedReply {
				attachment {
          id
        }
      }
      ... on SavedReplyFolder {
        id
      }
    }
  }
}

Steps to reproduce

use byebug inside the resolver
Try doing

(byebug) lookahead.selects?(:attachment)
false

to find that the attachment cannot be found on the lookahead

but whenever you do

(byebug) lookahead.selections.map(&:name)
[:__typename, :attachment, :id]

You'll find that the attachment field exists

Expected behavior

lookahead.selects?(:attachment) should return true

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Resolvers::SavedRepliesTreeResolver and reproduce the query with the Union type, comparing lookahead.selects?(:attachment) with lookahead.selections. Read the lookahead behavior for union selections and verify that attachment is recognized by selects? while the existing selections remain visible.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, rails, ruby
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.