Class: Souls::SoulsMutation

Inherits:
GraphQL::Schema::RelayClassicMutation
  • Object
show all
Defined in:
lib/souls/app/graphql/souls_mutation.rb

Instance Method Summary collapse

Instance Method Details

#auth_check(context) ⇒ Object

Raises:

  • (GraphQL::ExecutionError)


49
50
51
# File 'lib/souls/app/graphql/souls_mutation.rb', line 49

def auth_check(context)
  raise(GraphQL::ExecutionError, "You need to sign in!!") if context[:user].nil?
end

#get_instance_idObject



57
58
59
# File 'lib/souls/app/graphql/souls_mutation.rb', line 57

def get_instance_id
  `curl http://metadata.google.internal/computeMetadata/v1/instance/id -H Metadata-Flavor:Google`
end

#get_worker(worker_name: "") ⇒ Object



44
45
46
47
# File 'lib/souls/app/graphql/souls_mutation.rb', line 44

def get_worker(worker_name: "")
  workers = Souls.configuration.workers
  workers.filter { |n| n[:name] == worker_name }
end

#make_graphql_query(query: "newCommentMailer", args: {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/souls/app/graphql/souls_mutation.rb', line 18

def make_graphql_query(query: "newCommentMailer", args: {})
  if args.blank?
    query_string = %(query { #{query.to_s.underscore.camelize(:lower)} { response } })
  else
    inputs = ""
    args.each do |key, value|
      inputs +=
        if value.instance_of?(String)
          "#{key.to_s.underscore.camelize(:lower)}: \"#{value}\" "
        else
          "#{key.to_s.underscore.camelize(:lower)}: #{value} "
        end
    end
    query_string = %(query { #{query.to_s.underscore.camelize(:lower)}(#{inputs}) { response } })
  end
  query_string
end

#post_to_dev(worker_name: "", query_string: "") ⇒ Object



36
37
38
39
40
41
42
# File 'lib/souls/app/graphql/souls_mutation.rb', line 36

def post_to_dev(worker_name: "", query_string: "")
  app = Souls.configuration.app
  port = get_worker(worker_name: "souls-#{app}-#{worker_name}")[0][:port]
  endpoint = Souls.configuration.endpoint
  res = Net::HTTP.post_form(URI.parse("http://localhost:#{port}#{endpoint}"), { query: query_string })
  res.body
end

#production?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/souls/app/graphql/souls_mutation.rb', line 53

def production?
  ENV["RACK_ENV"] == "production"
end

#publish_pubsub_queue(topic_name: "send-mail-job", message: "text!") ⇒ Object



12
13
14
15
16
# File 'lib/souls/app/graphql/souls_mutation.rb', line 12

def publish_pubsub_queue(topic_name: "send-mail-job", message: "text!")
  pubsub = Google::Cloud::Pubsub.new(project: ENV["SOULS_GCP_PROJECT_ID"])
  topic = pubsub.topic(topic_name)
  topic.publish(message)
end

#souls_fb_auth(token:) ⇒ Object

Raises:

  • (ArgumentError)


3
4
5
6
7
8
9
10
# File 'lib/souls/app/graphql/souls_mutation.rb', line 3

def souls_fb_auth(token:)
  FirebaseIdToken::Certificates.request!
  sleep(3) if ENV["RACK_ENV"] == "development"
  user = FirebaseIdToken::Signature.verify(token)
  raise(ArgumentError, "Invalid or Missing Token") if user.blank?

  user
end