bearcat 1.5.36 → 1.5.37
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bearcat/client/graph_ql.rb +55 -5
- data/lib/bearcat/client.rb +13 -0
- data/lib/bearcat/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d158f0297de70f3ab0168d9eca3f0524ec3ab604ac8a4e756e0b07269a0e6e3
|
4
|
+
data.tar.gz: 07dd1d001f4bfc6248235be4f208782ad136a8af8223aed2e71ae60cc82fc9a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 050c5d4b285c4ec8a341b5bfdcc71d02837c8b7ffe5324ac77fef1bd17c77497273c7e366c608565a9dbe264e003b41c20c235d1fa328c774c4f831149e943c4
|
7
|
+
data.tar.gz: 3d9b79d660565eab8fe498d80d46d3ecd0553abd3d15b5d9be95038f7a781563fa44e2ab16f2505c267de725ed02473e739ec560d5de06ede75b1e2f05c20599
|
@@ -1,17 +1,67 @@
|
|
1
1
|
module Bearcat
|
2
|
+
class GraphqlError < StandardError
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
def initialize(message, response: nil)
|
6
|
+
super(message)
|
7
|
+
@response = response
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
2
11
|
class Client < Footrest::Client
|
3
|
-
# Request body format should be:
|
12
|
+
# Request body format should be:
|
13
|
+
# - { query: "query string" }
|
14
|
+
# - "query string"
|
15
|
+
# - "path/to/gql/file", may be absolute, relative to application root, or relative to `app/graphql`. `.gql` extension is optional.
|
4
16
|
module GraphQL
|
5
|
-
|
6
|
-
def graphql_query(query)
|
17
|
+
def graphql_query(query, args = {})
|
7
18
|
if query.is_a?(String)
|
19
|
+
if /\A\w+\Z/.match?(query) && !query.include?("{")
|
20
|
+
query = query.underscore
|
21
|
+
@@gql_cache ||= {}
|
22
|
+
|
23
|
+
query = cache_on_class("gql:#{query}") do
|
24
|
+
paths = []
|
25
|
+
|
26
|
+
pn = Pathname.new(query)
|
27
|
+
if pn.absolute?
|
28
|
+
paths << query
|
29
|
+
else
|
30
|
+
paths << Rails.root.join("app", "graphql", query)
|
31
|
+
paths << Rails.root.join(query)
|
32
|
+
end
|
33
|
+
|
34
|
+
paths = paths.flat_map do |path|
|
35
|
+
[path, "#{path}.gql"]
|
36
|
+
end
|
37
|
+
|
38
|
+
query = paths.find do |path|
|
39
|
+
File.exist?(path)
|
40
|
+
end
|
41
|
+
|
42
|
+
File.read(query)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
args.symbolize_keys!
|
47
|
+
|
48
|
+
query = query.gsub(/\{\{(.*?)\}\}/) do |_m|
|
49
|
+
match = Regexp.last_match
|
50
|
+
key = match[1].strip.to_sym
|
51
|
+
args[key]
|
52
|
+
end
|
53
|
+
|
8
54
|
query = {
|
9
55
|
query: query
|
10
56
|
}
|
11
57
|
end
|
12
|
-
post('/api/graphql', query)
|
13
|
-
end
|
14
58
|
|
59
|
+
result = post('/api/graphql', query)
|
60
|
+
raise GraphqlError.new("Error running GraphQL query:\n#{result["errors"].to_json}", response: result) if result["errors"].present?
|
61
|
+
|
62
|
+
# TODO: It'd be nice to unwrap and return result["data"] directly, but we want to keep backwards compatibility
|
63
|
+
result
|
64
|
+
end
|
15
65
|
end
|
16
66
|
end
|
17
67
|
end
|
data/lib/bearcat/client.rb
CHANGED
@@ -39,6 +39,19 @@ module Bearcat
|
|
39
39
|
connection.builder.delete(Footrest::RaiseFootrestErrors)
|
40
40
|
end
|
41
41
|
|
42
|
+
def self.cache_on_self(key, &block)
|
43
|
+
@cache ||= {}
|
44
|
+
if Rails.env.development? || Rails.env.test?
|
45
|
+
block.call
|
46
|
+
else
|
47
|
+
@cache[key] ||= block.call
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def cache_on_class(key, &block)
|
52
|
+
self.class.cache_on_self(key, &block)
|
53
|
+
end
|
54
|
+
|
42
55
|
protected
|
43
56
|
|
44
57
|
def rate_limited_request
|
data/lib/bearcat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bearcat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.37
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Instructure CustomDev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|