class Artemis::QueryGenerator

Public Instance Methods

generate_query_file() click to toggle source
# File lib/generators/artemis/query/query_generator.rb, line 13
def generate_query_file
  template "query.graphql", graphql_file_path
end

Private Instance Methods

arguments() click to toggle source
# File lib/generators/artemis/query/query_generator.rb, line 35
def arguments
  target_query.arguments
end
graphql_file_path() click to toggle source
# File lib/generators/artemis/query/query_generator.rb, line 27
def graphql_file_path
  "app/operations/#{service_name.underscore}/#{qualified_name}.graphql"
end
qualified_name() click to toggle source
# File lib/generators/artemis/query/query_generator.rb, line 61
def qualified_name
  graphql_file_name.presence || query_name
end
query_name() click to toggle source

def generate_text_fixture_file

template "fixture.yml", text_fixture_path

end

# File lib/generators/artemis/query/query_generator.rb, line 23
def query_name
  query_type.underscore
end
schema() click to toggle source
# File lib/generators/artemis/query/query_generator.rb, line 44
def schema
  service_name.camelize.constantize.endpoint.schema
end
service_name() click to toggle source
# File lib/generators/artemis/query/query_generator.rb, line 48
def service_name
  options['service'].presence || begin
    services = Artemis::GraphQLEndpoint.registered_services

    if services.size == 1
      services.first
    else
      fail "Please specify a service name (available services: #{services.join(", ")}):\n\n" \
           "  rails g artemis:query #{query_type} #{graphql_file_name} --service SERVICE"
    end
  end
end
target_query() click to toggle source
# File lib/generators/artemis/query/query_generator.rb, line 39
def target_query
  schema.find("Query").fields[query_type] ||
    raise(GraphQL::Schema::Finder::MemberNotFoundError, "Could not find type `#{query_type}` in schema.")
end
text_fixture_path() click to toggle source
# File lib/generators/artemis/query/query_generator.rb, line 31
def text_fixture_path
  File.join(Artemis::Railtie.config.artemis.fixture_path, service_name.underscore, "#{qualified_name}.yml")
end