Class: MockServer::GraphQLBody

Inherits:
Object
  • Object
show all
Defined in:
lib/mockserver/models.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query:, operation_name: nil, variables_schema: nil, selection_set_match_type: nil, fields: nil, not_body: false, optional: false) ⇒ GraphQLBody

Returns a new instance of GraphQLBody.



664
665
666
667
668
669
670
671
672
673
# File 'lib/mockserver/models.rb', line 664

def initialize(query:, operation_name: nil, variables_schema: nil,
               selection_set_match_type: nil, fields: nil, not_body: false, optional: false)
  @query = query
  @operation_name = operation_name
  @variables_schema = variables_schema
  @selection_set_match_type = selection_set_match_type
  @fields = fields
  @not_body = not_body
  @optional = optional
end

Instance Attribute Details

#fieldsObject

selection_set_match_type selects how the query's selection set is matched (NORMALISED_STRING / AST_EXACT / AST_SUBSET) and fields is the array of top-level field names the matcher restricts to, mirroring the server GraphQLBodyDTO selectionSetMatchType / fields (the GRAPHQL body's fields is a plain string array, distinct from the MULTIPART body's keyToMultiValue fields map — the server discriminates the two by the body type).



661
662
663
# File 'lib/mockserver/models.rb', line 661

def fields
  @fields
end

#not_bodyObject

selection_set_match_type selects how the query's selection set is matched (NORMALISED_STRING / AST_EXACT / AST_SUBSET) and fields is the array of top-level field names the matcher restricts to, mirroring the server GraphQLBodyDTO selectionSetMatchType / fields (the GRAPHQL body's fields is a plain string array, distinct from the MULTIPART body's keyToMultiValue fields map — the server discriminates the two by the body type).



661
662
663
# File 'lib/mockserver/models.rb', line 661

def not_body
  @not_body
end

#operation_nameObject

selection_set_match_type selects how the query's selection set is matched (NORMALISED_STRING / AST_EXACT / AST_SUBSET) and fields is the array of top-level field names the matcher restricts to, mirroring the server GraphQLBodyDTO selectionSetMatchType / fields (the GRAPHQL body's fields is a plain string array, distinct from the MULTIPART body's keyToMultiValue fields map — the server discriminates the two by the body type).



661
662
663
# File 'lib/mockserver/models.rb', line 661

def operation_name
  @operation_name
end

#optionalObject

selection_set_match_type selects how the query's selection set is matched (NORMALISED_STRING / AST_EXACT / AST_SUBSET) and fields is the array of top-level field names the matcher restricts to, mirroring the server GraphQLBodyDTO selectionSetMatchType / fields (the GRAPHQL body's fields is a plain string array, distinct from the MULTIPART body's keyToMultiValue fields map — the server discriminates the two by the body type).



661
662
663
# File 'lib/mockserver/models.rb', line 661

def optional
  @optional
end

#queryObject

selection_set_match_type selects how the query's selection set is matched (NORMALISED_STRING / AST_EXACT / AST_SUBSET) and fields is the array of top-level field names the matcher restricts to, mirroring the server GraphQLBodyDTO selectionSetMatchType / fields (the GRAPHQL body's fields is a plain string array, distinct from the MULTIPART body's keyToMultiValue fields map — the server discriminates the two by the body type).



661
662
663
# File 'lib/mockserver/models.rb', line 661

def query
  @query
end

#selection_set_match_typeObject

selection_set_match_type selects how the query's selection set is matched (NORMALISED_STRING / AST_EXACT / AST_SUBSET) and fields is the array of top-level field names the matcher restricts to, mirroring the server GraphQLBodyDTO selectionSetMatchType / fields (the GRAPHQL body's fields is a plain string array, distinct from the MULTIPART body's keyToMultiValue fields map — the server discriminates the two by the body type).



661
662
663
# File 'lib/mockserver/models.rb', line 661

def selection_set_match_type
  @selection_set_match_type
end

#variables_schemaObject

selection_set_match_type selects how the query's selection set is matched (NORMALISED_STRING / AST_EXACT / AST_SUBSET) and fields is the array of top-level field names the matcher restricts to, mirroring the server GraphQLBodyDTO selectionSetMatchType / fields (the GRAPHQL body's fields is a plain string array, distinct from the MULTIPART body's keyToMultiValue fields map — the server discriminates the two by the body type).



661
662
663
# File 'lib/mockserver/models.rb', line 661

def variables_schema
  @variables_schema
end

Class Method Details

.from_hash(data) ⇒ Object



686
687
688
689
690
691
692
693
694
695
696
697
698
# File 'lib/mockserver/models.rb', line 686

def self.from_hash(data)
  return nil if data.nil?

  new(
    query:                    data['query'] || '',
    operation_name:           data['operationName'],
    variables_schema:         data['variablesSchema'],
    selection_set_match_type: data['selectionSetMatchType'],
    fields:                   data['fields'],
    not_body:                 data.fetch('not', false),
    optional:                 data.fetch('optional', false)
  )
end

Instance Method Details

#to_hObject



675
676
677
678
679
680
681
682
683
684
# File 'lib/mockserver/models.rb', line 675

def to_h
  result = { 'type' => 'GRAPHQL', 'query' => @query }
  result['operationName'] = @operation_name if @operation_name
  result['variablesSchema'] = @variables_schema if @variables_schema
  result['selectionSetMatchType'] = @selection_set_match_type unless @selection_set_match_type.nil?
  result['fields'] = @fields unless @fields.nil?
  result['not'] = true if @not_body
  result['optional'] = true if @optional
  result
end