Sha256: 7a965ba45bc80881eb948e653ab42fb1cee212af95aea2b1542027129126148b

Contents?: true

Size: 1021 Bytes

Versions: 14

Compression:

Stored size: 1021 Bytes

Contents

# frozen_string_literal: true
RSpec.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 ->(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

14 entries across 14 versions & 2 rubygems

Version Path
decidim-api-0.1.0 lib/decidim/api/test/type_context.rb
decidim-0.1.0 decidim-api/lib/decidim/api/test/type_context.rb
decidim-api-0.0.8.1 lib/decidim/api/test/type_context.rb
decidim-0.0.8.1 decidim-api/lib/decidim/api/test/type_context.rb
decidim-api-0.0.8 lib/decidim/api/test/type_context.rb
decidim-api-0.0.7 lib/decidim/api/test/type_context.rb
decidim-0.0.7 decidim-api/lib/decidim/api/test/type_context.rb
decidim-api-0.0.6 lib/decidim/api/test/type_context.rb
decidim-0.0.6 decidim-api/lib/decidim/api/test/type_context.rb
decidim-api-0.0.5 lib/decidim/api/test/type_context.rb
decidim-0.0.5 decidim-api/lib/decidim/api/test/type_context.rb
decidim-0.0.4 decidim-api/lib/decidim/api/test/type_context.rb
decidim-api-0.0.3 lib/decidim/api/test/type_context.rb
decidim-0.0.3 decidim-api/lib/decidim/api/test/type_context.rb