Skip to content

Does not work across multiplexed queries #90

@TSMMark

Description

@TSMMark

This library is fantastic and thanks for publishing it!

In my testing, IDs are not always aggregated across multiple queries when Schema#multiplex is used. The promises do resolve correctly, but one DB query is made per multiplexed gql query.

I found a test in this repo, which runs queries with multiplex and uses QueryNotifier.subscriber to assert that only 1 query is made, but my loader does not behave.

Current gem versions:

gem "graphql", "=1.6.0"
gem "graphql-batch", "=0.3.9"

The loader in question is very simple:

module Loaders
  class Single < ::GraphQL::Batch::Loader

    attr_reader :model, :options, :key

    def initialize(model_arg, options_arg = {})
      @model = model_arg
      @options = options_arg
      @key = options.fetch(:key, :id)
    end

    def perform(ids)
      model.where(key => ids).all.each(&method(:fulfill_record))
      ids.reject(&method(:fulfilled?)).each(&method(:fulfill_nil))
    end

    private

    def fulfill_record(record)
      fulfill(record.send(key), record)
    end

    def fulfill_nil(id)
      fulfill(id, nil)
    end

  end
end

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions