Class: Weaviate::GraphQL

Inherits:
Base
  • Object
show all
Defined in:
lib/weaviate/graphql.rb,
sig/weaviate.rbs

Constant Summary collapse

PATH =
"graphql"

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Weaviate::Base

Instance Method Details

#execute(query) ⇒ json

Execute a GraphQL query and return the "data" portion of the response.

Parameters:

  • query (String)

Returns:

  • (json)

Raises:



8
9
10
11
12
13
14
15
16
17
# File 'lib/weaviate/graphql.rb', line 8

def execute(query)
  response = client.connection.post(PATH) do |req|
    req.body = {query: query}
  end

  errors = response.body["errors"]
  raise Weaviate::GraphQLError.new(errors) if errors && !errors.empty?

  response.body["data"]
end