mj 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -1
- data/README.md +32 -0
- data/lib/mj/alternative_file/thor_command.rb +1 -0
- data/lib/mj/cli.rb +4 -0
- data/lib/mj/graphql/client.rb +16 -0
- data/lib/mj/graphql/commands/query_file_command.rb +17 -0
- data/lib/mj/graphql/commands/query_file_command_handler.rb +17 -0
- data/lib/mj/graphql/request.rb +44 -0
- data/lib/mj/graphql/request_factory.rb +36 -0
- data/lib/mj/graphql/thor_command.rb +18 -0
- data/lib/mj/version.rb +1 -1
- data/mj.gemspec +1 -0
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59cf5e3a74d7c41f0b5b2c3789d85987b3393eccd110dc4741a3bdff59058827
|
4
|
+
data.tar.gz: c0772655f097653bbbd719e1791791e97bd30349973febf410ae54be24f470ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f385ad6f1354b967cde4c98e63b96b1e918c406bd6009e676bac8d61f30f4df1ebffe73d3b34ac35c246f383338b0224cf7bf1d3d606176fe7f3ac95d40df74
|
7
|
+
data.tar.gz: 4ce923b46dbf190b9b233512fae4fc9163a7853926e29aa4e7f9f3cfad1ddfd274be89f0c1052b4dcaa4bde42deced0cf9e7cf3ce425154153b2dc2212202c74
|
data/Gemfile.lock
CHANGED
@@ -1,25 +1,37 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mj (0.
|
4
|
+
mj (0.7.0)
|
5
|
+
koine-rest_client
|
5
6
|
thor (~> 1.2.1)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
11
|
+
addressable (2.8.6)
|
12
|
+
public_suffix (>= 2.0.2, < 6.0)
|
10
13
|
ast (2.4.2)
|
11
14
|
awesome_print (1.9.2)
|
12
15
|
coderay (1.1.3)
|
13
16
|
diff-lcs (1.5.0)
|
14
17
|
docile (1.4.0)
|
18
|
+
httparty (0.21.0)
|
19
|
+
mini_mime (>= 1.0.0)
|
20
|
+
multi_xml (>= 0.5.2)
|
21
|
+
koine-rest_client (1.1.1)
|
22
|
+
addressable (>= 2.3)
|
23
|
+
httparty (>= 0.17.0)
|
15
24
|
koine-test_runner (0.4.0)
|
16
25
|
method_source (1.0.0)
|
26
|
+
mini_mime (1.1.5)
|
27
|
+
multi_xml (0.6.0)
|
17
28
|
parallel (1.21.0)
|
18
29
|
parser (3.1.1.0)
|
19
30
|
ast (~> 2.4.1)
|
20
31
|
pry (0.14.2)
|
21
32
|
coderay (~> 1.1)
|
22
33
|
method_source (~> 1.0)
|
34
|
+
public_suffix (5.0.4)
|
23
35
|
rainbow (3.1.1)
|
24
36
|
rake (13.0.6)
|
25
37
|
regexp_parser (2.2.1)
|
data/README.md
CHANGED
@@ -28,6 +28,38 @@ Or install it yourself as:
|
|
28
28
|
mj help
|
29
29
|
```
|
30
30
|
|
31
|
+
### GraphQl
|
32
|
+
|
33
|
+
```
|
34
|
+
bundle exec mj graphql query_file AccountUsers.graphql | jq
|
35
|
+
```
|
36
|
+
|
37
|
+
Your graqphql fiel is a regular file with variables at the top:
|
38
|
+
|
39
|
+
```graphql
|
40
|
+
# gql-endpoint: http://api.myapi.me/graphql
|
41
|
+
# gql-header: Authorization: Bearer cb923f33617877578961a19cf4566ec2
|
42
|
+
# gql-header: Content-Type: application/json
|
43
|
+
# gql-header: Cookie: ajs_user_id=ae3948ee-345e-47f2-8e2f-54277858e2c2; ajs_anonymous_id=30880a34-276e-4a86-a1d3-8869d1669199; _ga=GA1.1.649149230.1706868690; browser_id=14af87a406ec54cbe9804ea25c8f0a84; _ga_TZKSP5TS45=GS1.1.1708606615.26.1.1708606911.0.0.0
|
44
|
+
# gql-variables: { "input": { "id": "yTXuIgoU88LKUNDLSVPFFjOSkgxlyyuSrNki3GY=" } }
|
45
|
+
|
46
|
+
query QueryAccountUsers(
|
47
|
+
$input: AccountInput!
|
48
|
+
) {
|
49
|
+
account(input: $input) {
|
50
|
+
users {
|
51
|
+
id
|
52
|
+
name
|
53
|
+
}
|
54
|
+
errors {
|
55
|
+
path
|
56
|
+
message
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
```
|
61
|
+
|
62
|
+
|
31
63
|
### Alternative file
|
32
64
|
|
33
65
|
Examples:
|
@@ -59,6 +59,7 @@ module Mj
|
|
59
59
|
resolvers.add(Resolvers::Ruby::RailsControllerResolver.new)
|
60
60
|
resolvers.add(Resolvers::Ruby::ViewComponentResolver.new)
|
61
61
|
resolvers.add(Resolvers::Ruby::PackwerkResolver.new)
|
62
|
+
resolvers.add(Resolvers::Ruby::VendoredGemsResolver.new)
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
data/lib/mj/cli.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require "thor"
|
4
4
|
require_relative "version"
|
5
5
|
require_relative "alternative_file/thor_command"
|
6
|
+
require_relative "graphql/thor_command"
|
6
7
|
|
7
8
|
module Mj
|
8
9
|
class Cli < Thor
|
@@ -17,5 +18,8 @@ module Mj
|
|
17
18
|
|
18
19
|
desc "alternative_file", "Lists alternative files"
|
19
20
|
subcommand "alternative_file", AlternativeFile::ThorCommand
|
21
|
+
|
22
|
+
desc "graphql", "CLI client for GraphQL"
|
23
|
+
subcommand "graphql", GraphQL::ThorCommand
|
20
24
|
end
|
21
25
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "koine/rest_client"
|
4
|
+
|
5
|
+
module Mj
|
6
|
+
module GraphQL
|
7
|
+
class Client
|
8
|
+
def send(request)
|
9
|
+
base_url = request.endpoint.split("/graphql").first
|
10
|
+
base_request = Koine::RestClient::Request.new(base_url: base_url)
|
11
|
+
http_client = Koine::RestClient::Client.new(base_request: base_request)
|
12
|
+
http_client.post("/graphql", request.to_h, headers: request.headers)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mj
|
4
|
+
module GraphQL
|
5
|
+
module Commands
|
6
|
+
class QueryFileCommand
|
7
|
+
attr_reader :file
|
8
|
+
attr_reader :options
|
9
|
+
|
10
|
+
def initialize(file, options)
|
11
|
+
@file = file
|
12
|
+
@options = options
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../request_factory"
|
4
|
+
require_relative "../client"
|
5
|
+
|
6
|
+
module Mj
|
7
|
+
module GraphQL
|
8
|
+
module Commands
|
9
|
+
class QueryFileCommandHandler
|
10
|
+
def handle(command)
|
11
|
+
request = RequestFactory.new.from_file(command.file)
|
12
|
+
Client.new.send(request)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mj
|
4
|
+
module GraphQL
|
5
|
+
class Request
|
6
|
+
attr_reader :endpoint, :headers, :query, :variables
|
7
|
+
|
8
|
+
def initialize(endpoint: nil, query: nil, variables: {}, headers: {})
|
9
|
+
@endpoint = endpoint
|
10
|
+
@query = query
|
11
|
+
@variables = variables
|
12
|
+
@headers = headers
|
13
|
+
end
|
14
|
+
|
15
|
+
def with_header(name, value)
|
16
|
+
with(:headers, headers.merge(name => value))
|
17
|
+
end
|
18
|
+
|
19
|
+
def with_variables(variables)
|
20
|
+
with(:variables, variables)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_h
|
24
|
+
{
|
25
|
+
query: query,
|
26
|
+
variables: variables
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def with(variable, value)
|
33
|
+
config = {
|
34
|
+
endpoint: endpoint,
|
35
|
+
query: query,
|
36
|
+
variables: variables,
|
37
|
+
headers: headers
|
38
|
+
}.merge(variable => value)
|
39
|
+
|
40
|
+
self.class.new(**config)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "request"
|
4
|
+
|
5
|
+
module Mj
|
6
|
+
module GraphQL
|
7
|
+
class RequestFactory
|
8
|
+
def from_file(file) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength
|
9
|
+
contents = File.read(file)
|
10
|
+
comments = contents.split("\n").take_while { |line| line.match(/^#/) }.join("\n")
|
11
|
+
query = contents.split("\n").drop_while { |line| line.match(/^#/) }.join("\n")
|
12
|
+
endpoint = comments.match(/# gql-endpoint: (.+)/)&.captures&.first
|
13
|
+
|
14
|
+
request = Request.new(query: query, endpoint: endpoint)
|
15
|
+
|
16
|
+
headers = comments.split("\n")
|
17
|
+
.select { |line| line.match(/^# gql-header:/) }
|
18
|
+
.map { |line| line.split("gql-header:")[1..].join.strip }
|
19
|
+
|
20
|
+
headers.map do |value|
|
21
|
+
values = value.split(":").map(&:strip)
|
22
|
+
request = request.with_header(*values)
|
23
|
+
end
|
24
|
+
|
25
|
+
variables_string = comments.match(/# gql-variables:\s?(.+)/)&.captures&.first
|
26
|
+
|
27
|
+
if variables_string
|
28
|
+
variables = JSON.parse(variables_string)
|
29
|
+
request = request.with_variables(variables)
|
30
|
+
end
|
31
|
+
|
32
|
+
request
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "commands/query_file_command_handler"
|
4
|
+
require_relative "commands/query_file_command"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module Mj
|
8
|
+
module GraphQL
|
9
|
+
class ThorCommand < Thor
|
10
|
+
desc "query_file <file>", "Execute a query based on a .graqphql file"
|
11
|
+
def query_file(file)
|
12
|
+
handler = Commands::QueryFileCommandHandler.new
|
13
|
+
data = handler.handle(Commands::QueryFileCommand.new(file, options))
|
14
|
+
$stdout.puts JSON.generate(data)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/mj/version.rb
CHANGED
data/mj.gemspec
CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
32
|
spec.require_paths = ["lib"]
|
33
33
|
|
34
|
+
spec.add_dependency "koine-rest_client"
|
34
35
|
spec.add_dependency "thor", "~> 1.2.1"
|
35
36
|
|
36
37
|
# For more information and examples about making a new gem, check out our
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Jacobus
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: koine-rest_client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: thor
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,6 +73,12 @@ files:
|
|
59
73
|
- lib/mj/alternative_file/resolvers/ruby/view_component_resolver.rb
|
60
74
|
- lib/mj/alternative_file/thor_command.rb
|
61
75
|
- lib/mj/cli.rb
|
76
|
+
- lib/mj/graphql/client.rb
|
77
|
+
- lib/mj/graphql/commands/query_file_command.rb
|
78
|
+
- lib/mj/graphql/commands/query_file_command_handler.rb
|
79
|
+
- lib/mj/graphql/request.rb
|
80
|
+
- lib/mj/graphql/request_factory.rb
|
81
|
+
- lib/mj/graphql/thor_command.rb
|
62
82
|
- lib/mj/version.rb
|
63
83
|
- mj.gemspec
|
64
84
|
- sig/mj.rbs
|