Sha256: 05cafa405eed2f122ee00db0fdb9a545d7a8cfaeb90c74a1243b085b964afb05

Contents?: true

Size: 831 Bytes

Versions: 12

Compression:

Stored size: 831 Bytes

Contents

module NulogyGraphqlApi
  module GraphqlHelpers
    def execute_graphql(query, schema, variables: {}, context: {})
      camelized_variables = variables.deep_transform_keys! { |key| key.to_s.camelize(:lower) } || {}

      response = schema.execute(
        query,
        variables: camelized_variables,
        context: context,
        operation_name: nil
      )

      response.to_h.deep_symbolize_keys
    end

    def request_graphql(url, query, variables: {}, headers: {})
      params = { query: query, variables: variables }.to_json
      default_headers = {
        CONTENT_TYPE: "application/json",
        HTTP_AUTHORIZATION: basic_auth_token(default_user.login)
      }

      post url, params: params, headers: default_headers.merge(headers)

      JSON.parse(response.body, symbolize_names: true)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
nulogy_graphql_api-3.0.1 lib/nulogy_graphql_api/rspec/graphql_helpers.rb
nulogy_graphql_api-2.2.0 lib/nulogy_graphql_api/rspec/graphql_helpers.rb
nulogy_graphql_api-2.1.3 lib/nulogy_graphql_api/rspec/graphql_helpers.rb
nulogy_graphql_api-2.1.2 lib/nulogy_graphql_api/rspec/graphql_helpers.rb
nulogy_graphql_api-2.1.1 lib/nulogy_graphql_api/rspec/graphql_helpers.rb
nulogy_graphql_api-2.1.0 lib/nulogy_graphql_api/rspec/graphql_helpers.rb
nulogy_graphql_api-2.0.1 lib/nulogy_graphql_api/rspec/graphql_helpers.rb
nulogy_graphql_api-2.0.0 lib/nulogy_graphql_api/rspec/graphql_helpers.rb
nulogy_graphql_api-1.1.1 lib/nulogy_graphql_api/rspec/graphql_helpers.rb
nulogy_graphql_api-1.1.0 lib/nulogy_graphql_api/rspec/graphql_helpers.rb
nulogy_graphql_api-1.0.0 lib/nulogy_graphql_api/rspec/graphql_helpers.rb
nulogy_graphql_api-0.6.0 lib/nulogy_graphql_api/rspec/graphql_helpers.rb