bearcat 1.5.36 → 1.5.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bearcat/client/graph_ql.rb +55 -5
- data/lib/bearcat/client.rb +13 -0
- data/lib/bearcat/redis_connection.rb +0 -0
- data/lib/bearcat/spec_helpers.rb +5 -2
- 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: 93e58f81247055b990fa17d5d98f823c253a28c383e26a8bb5e908befb5d845d
|
4
|
+
data.tar.gz: a1179323c73208512485325e1c4263e4e49bb9e3c7d9682c5147e3a3d9fc32aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d26752bb5749819f4aedf02873ee118834b6bc69aaaec52e8ae8281dc9fe239e4947ae401a9022850ba21f2c06d7e53f1907a8cc90938b4602af42918eda89e1
|
7
|
+
data.tar.gz: ba0107db287c5962e3d3291b2b8dc0695887ce74d14f4217c2956e5d648c85219249564db5fba43d7b347e238d1d654001a5e1574b5cc0e15e6aa797af9235e0
|
@@ -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
|
File without changes
|
data/lib/bearcat/spec_helpers.rb
CHANGED
@@ -97,10 +97,13 @@ module Bearcat::SpecHelpers
|
|
97
97
|
end
|
98
98
|
when String
|
99
99
|
raise "Cannot use method :auto when passing string endpoint" if method == :auto
|
100
|
-
|
100
|
+
endpoint = Regexp.escape(endpoint)
|
101
|
+
endpoint = endpoint.gsub("\\*\\*", ".+")
|
102
|
+
endpoint = endpoint.gsub("\\*", "[^/]+")
|
103
|
+
{ method: method, url: endpoint }
|
101
104
|
when Regexp
|
102
105
|
raise "Cannot use method :auto when passing regex endpoint" if method == :auto
|
103
|
-
{ method: method, url:
|
106
|
+
{ method: method, url: endpoint.to_s }
|
104
107
|
end
|
105
108
|
end
|
106
109
|
|
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.38
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Instructure CustomDev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|