Sha256: c3c31288d9f578d60b741adfd0f977e19606ff2bbd1a40fdbf7243fe47fcfc91

Contents?: true

Size: 1 KB

Versions: 27

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

shared_context "graphql type" do
  let!(:current_organization) { create(:organization) }
  let!(:current_user) { create(:user, organization: current_organization) }
  let(:model) { OpenStruct.new({}) }

  let(:schema) do
    resolver = ->(_obj, _args, _ctx) { model }
    type_class = described_class

    query_type = GraphQL::ObjectType.define do
      name "FakeTestQuery"

      field :type, !type_class do
        resolve resolver
      end
    end

    GraphQL::Schema.define do
      query query_type
      resolve_type ->(_type, _obj, _ctx) {}
    end
  end

  let(:response) do
    execute_query "{ type #{query}}"
  end

  def execute_query(query, variables = {})
    result = schema.execute(
      query,
      context: {
        current_organization: current_organization,
        current_user: current_user
      },
      variables: variables
    )

    raise Exception, result["errors"].map { |e| e["message"] }.join(", ") if result["errors"]
    result["data"]["type"]
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
decidim-api-0.7.4 lib/decidim/api/test/type_context.rb
decidim-api-0.7.3 lib/decidim/api/test/type_context.rb
decidim-api-0.7.2 lib/decidim/api/test/type_context.rb
decidim-api-0.7.1 lib/decidim/api/test/type_context.rb
decidim-api-0.7.0 lib/decidim/api/test/type_context.rb
decidim-api-0.6.8 lib/decidim/api/test/type_context.rb
decidim-0.6.8 decidim-api/lib/decidim/api/test/type_context.rb
decidim-api-0.6.7 lib/decidim/api/test/type_context.rb
decidim-0.6.7 decidim-api/lib/decidim/api/test/type_context.rb
decidim-api-0.6.6 lib/decidim/api/test/type_context.rb
decidim-0.6.6 decidim-api/lib/decidim/api/test/type_context.rb
decidim-api-0.6.5 lib/decidim/api/test/type_context.rb
decidim-0.6.5 decidim-api/lib/decidim/api/test/type_context.rb
decidim-api-0.6.4 lib/decidim/api/test/type_context.rb
decidim-0.6.4 decidim-api/lib/decidim/api/test/type_context.rb
decidim-api-0.6.3 lib/decidim/api/test/type_context.rb
decidim-0.6.3 decidim-api/lib/decidim/api/test/type_context.rb
decidim-api-0.6.2 lib/decidim/api/test/type_context.rb
decidim-0.6.2 decidim-api/lib/decidim/api/test/type_context.rb
decidim-api-0.6.1 lib/decidim/api/test/type_context.rb