Class: PersistedQueries::AddOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/persisted_queries/add_operation.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:, query:, hash:, store:) ⇒ AddOperation

Returns a new instance of AddOperation.



5
6
7
8
9
10
# File 'lib/persisted_queries/add_operation.rb', line 5

def initialize(client:, query:, hash:, store:)
  @client = client
  @query = query
  @hash = hash
  @store = store
end

Instance Method Details

#performObject



12
13
14
15
16
17
18
19
20
# File 'lib/persisted_queries/add_operation.rb', line 12

def perform
  document = GraphQL.parse(query)
  errors = store.schema.validate(document) # Use validation to assert that the document has only 1 valid operation
  # digest = Digest::MD5.hexdigest(document.to_query_string)
  name = document.definitions[0].name

  filename = store.client_path(client.underscore) + "#{name.underscore}_#{hash}.graphql"
  File.open(filename, "w") { |file| file.write(document.to_query_string) }
end