Class: Mj::GraphQL::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/mj/graphql/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint: nil, query: nil, variables: {}, headers: {}) ⇒ Request

Returns a new instance of Request.



8
9
10
11
12
13
# File 'lib/mj/graphql/request.rb', line 8

def initialize(endpoint: nil, query: nil, variables: {}, headers: {})
  @endpoint = endpoint
  @query = query
  @variables = variables
  @headers = headers
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



6
7
8
# File 'lib/mj/graphql/request.rb', line 6

def endpoint
  @endpoint
end

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/mj/graphql/request.rb', line 6

def headers
  @headers
end

#queryObject (readonly)

Returns the value of attribute query.



6
7
8
# File 'lib/mj/graphql/request.rb', line 6

def query
  @query
end

#variablesObject (readonly)

Returns the value of attribute variables.



6
7
8
# File 'lib/mj/graphql/request.rb', line 6

def variables
  @variables
end

Instance Method Details

#to_hObject



23
24
25
26
27
28
# File 'lib/mj/graphql/request.rb', line 23

def to_h
  {
    query: query,
    variables: variables
  }
end

#with_header(name, value) ⇒ Object



15
16
17
# File 'lib/mj/graphql/request.rb', line 15

def with_header(name, value)
  with(:headers, headers.merge(name => value))
end

#with_variables(variables) ⇒ Object



19
20
21
# File 'lib/mj/graphql/request.rb', line 19

def with_variables(variables)
  with(:variables, variables)
end