Sha256: f7b3af66891177942f2b65066e320e837f46fdeb24a318e39027b9b7f2003052

Contents?: true

Size: 835 Bytes

Versions: 4

Compression:

Stored size: 835 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

4 entries across 4 versions & 1 rubygems

Version Path
nulogy_graphql_api-0.5.3 lib/nulogy_graphql_api/rspec/graphql_helpers.rb
nulogy_graphql_api-0.5.1 lib/nulogy_graphql_api/rspec/graphql_helpers.rb
nulogy_graphql_api-0.5.0 lib/nulogy_graphql_api/rspec/graphql_helpers.rb
nulogy_graphql_api-0.4.0 lib/nulogy_graphql_api/rspec/graphql_helpers.rb