graphql_tag_pluck 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 47adc95bd92376623769305b204563c4c4426aaaef907168f9808f68f188e664
4
+ data.tar.gz: 339f872ef8f6b8b292f212cf5f4c81541b98d679bfd556f5f6bf32d47f4699c1
5
+ SHA512:
6
+ metadata.gz: a4ba7fc5f68fc3b6588d33f175aff496e458f0f94dae6c3af167ac911aa85234eacfb047fbe88529998d0bce2497489cf19dc73cf9a5f47815466767ee11ea56
7
+ data.tar.gz: 2eb339b83ccd461ad5cd9efe3428d21392fe2e358a8822e282daf9a3460dc75b7121ad4efcbccf3bc8d711c8b8daaf465d1dcf096a029df9a3f2115ff991733a
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at indigo.lain@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in graphql_tag_pluck.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 indigolain
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # GraphqlTagPluck
2
+
3
+ A gem for plucking GraphQL queries / mutations / fragments defined by heredocs inside files and exporting them to json file.
4
+ Install this gem and run the following rake task to get the exported json file containing the list of GraphQL queries / mutations / fragments.
5
+
6
+ ```sh
7
+ bundle exec rake graphql_tag_pluck:generate_graphql_operation_list
8
+ ```
9
+
10
+ You can configure the following options by creating `.graphqltagpluckconfig.yaml` and specifying them inside.
11
+
12
+ - graphql_heredoc_identifiers
13
+ - An array of heredoc identifiers used to define GraphQL queries / mutations / fragments
14
+ - default: `["GRAPHQL", "GQL"]`
15
+ - file_glob_pattern
16
+ - A glob pattern to search for the heredocs containing GraphQL queries / mutations / fragments
17
+ - default: `"#{Dir.pwd}/**/*.rb"`
18
+ - output_path
19
+ - The destination of exported json file path
20
+ - default: `"__generated__/graphql_operation_list.json"`
21
+
22
+ ## Installation
23
+
24
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
25
+
26
+ Install the gem and add to the application's Gemfile by executing:
27
+
28
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
29
+
30
+ If bundler is not being used to manage dependencies, install the gem by executing:
31
+
32
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require './lib/graphql_tag_pluck'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: :spec
10
+
11
+ path = File.expand_path(__dir__)
12
+ Dir.glob("#{path}/lib/graphql_tag_pluck/tasks/**/*.rake").each { |f| import f }
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/graphql_tag_pluck/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "graphql_tag_pluck"
7
+ spec.version = GraphqlTagPluck::VERSION
8
+ spec.authors = ["indigolain"]
9
+ spec.email = ["indigo.lain@gmail.com"]
10
+
11
+ spec.summary = "Plucks GraphQL document from Ruby codes"
12
+ # spec.description = "TODO: Write a longer description or delete this line."
13
+ spec.homepage = "https://github.com/indigolain/graphql_tag_pluck"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/indigolain/graphql_tag_pluck"
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ spec.add_dependency "parser", "~> 3.3"
36
+ spec.add_dependency "graphql", "~> 2.0"
37
+ spec.add_dependency "yaml", "~> 0.1.0"
38
+
39
+ # For more information and examples about making a new gem, check out our
40
+ # guide at: https://bundler.io/guides/creating_gem.html
41
+ end
@@ -0,0 +1,4 @@
1
+ require 'graphql_tag_pluck'
2
+
3
+ path = File.expand_path(__dir__)
4
+ Dir.glob("#{path}/tasks/**/*.rake").each { |f| import f }
@@ -0,0 +1,34 @@
1
+ require "yaml"
2
+
3
+ module GraphqlTagPluck
4
+
5
+ class Config
6
+ CONFIG_FILE = File.expand_path(".graphqltagpluckconfig.yaml", Dir.pwd)
7
+
8
+ attr_reader :options
9
+
10
+ def self.load
11
+ new.load
12
+ end
13
+
14
+ def initialize
15
+ @options = {}
16
+ end
17
+
18
+ def load
19
+ load_file(CONFIG_FILE)
20
+ @options
21
+ end
22
+
23
+ private
24
+
25
+ def load_file(path)
26
+ if File.exist?(path)
27
+ YAML.load_file(path).each do |key, value|
28
+ key = key.to_sym
29
+ @options[key] = value
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,13 @@
1
+ require 'graphql_tag_pluck'
2
+ require 'rails'
3
+
4
+ module GraphqlTagPluck
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :graphql_tag_pluck
7
+
8
+ rake_tasks do
9
+ path = File.expand_path(__dir__)
10
+ Dir.glob("#{path}/tasks/**/*.rake").each { |f| puts f; load f }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+
3
+ namespace :graphql_tag_pluck do
4
+ task :generate_graphql_operation_list do
5
+ graphql_hash = GraphqlTagPluck.get_graphql_heredocs
6
+ file_path = GraphqlTagPluck.options[:output_path]
7
+ dirname = File.dirname(file_path)
8
+
9
+ unless File.directory?(dirname)
10
+ FileUtils.mkdir_p(dirname)
11
+ end
12
+
13
+ File.open(file_path, "w") do |f|
14
+ f.write(graphql_hash.to_json)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GraphqlTagPluck
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "graphql_tag_pluck/version"
4
+ require_relative "graphql_tag_pluck/config"
5
+ require_relative "graphql_tag_pluck/railtie" if defined?(Rails)
6
+ require "parser/current"
7
+ require "graphql"
8
+
9
+ module GraphqlTagPluck
10
+
11
+ class Error < StandardError; end
12
+
13
+ class << self
14
+ attr_accessor :options
15
+
16
+ def default_options
17
+ {
18
+ graphql_heredoc_identifiers: %w{GRAPHQL GQL},
19
+ file_glob_pattern: "#{Dir.pwd}/**/*.rb",
20
+ output_path: "__generated__/graphql_operation_list.json"
21
+ }
22
+ end
23
+
24
+ def get_graphql_heredocs
25
+ files = Dir.glob(GraphqlTagPluck.options[:file_glob_pattern])
26
+
27
+ {}.tap do |hash|
28
+ files.each do |file|
29
+ node = create_node_from_file(file)
30
+ parsed_node_array = parse_node_recursively(node)
31
+ next if parsed_node_array.nil?
32
+
33
+ parsed_node_array.flatten.compact.each do |graphql_doc_string|
34
+ parsed_graphql_doc_string = GraphQL.parse(graphql_doc_string)
35
+ parsed_graphql_doc_string.definitions.each do |definition|
36
+ hash[definition.name] = {
37
+ name: definition.name,
38
+ source: definition.to_query_string,
39
+ type: definition.instance_of?(GraphQL::Language::Nodes::FragmentDefinition) ? 'fragment' : definition.operation_type
40
+ }
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ def create_node_from_file(file_path)
48
+ file_string = File.read(file_path)
49
+ Parser::CurrentRuby.parse(file_string)
50
+ end
51
+
52
+ def parse_node_recursively(node)
53
+ return nil unless node.respond_to?(:loc)
54
+ return node.loc.heredoc_body.source if is_graphql_heredoc_node?(node)
55
+ return node.children.map {|child| parse_node_recursively(child) } if node.respond_to?(:children)
56
+ end
57
+
58
+ def is_graphql_heredoc_node?(node)
59
+ node.loc.instance_of?(Parser::Source::Map::Heredoc) &&
60
+ GraphqlTagPluck.options[:graphql_heredoc_identifiers].any? {|identifier| node.loc.expression.source.include?(identifier) }
61
+ end
62
+ end
63
+
64
+ self.options = default_options.merge(Config.load)
65
+ end
@@ -0,0 +1,4 @@
1
+ module GraphqlTagPluck
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graphql_tag_pluck
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - indigolain
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: graphql
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yaml
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.0
55
+ description:
56
+ email:
57
+ - indigo.lain@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".rspec"
63
+ - CODE_OF_CONDUCT.md
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - graphql_tag_pluck.gemspec
69
+ - lib/graphql_tag_pluck.rb
70
+ - lib/graphql_tag_pluck/Rakefile
71
+ - lib/graphql_tag_pluck/config.rb
72
+ - lib/graphql_tag_pluck/railtie.rb
73
+ - lib/graphql_tag_pluck/tasks/generate_graphql_operation_list.rake
74
+ - lib/graphql_tag_pluck/version.rb
75
+ - sig/graphql_tag_pluck.rbs
76
+ homepage: https://github.com/indigolain/graphql_tag_pluck
77
+ licenses:
78
+ - MIT
79
+ metadata:
80
+ homepage_uri: https://github.com/indigolain/graphql_tag_pluck
81
+ source_code_uri: https://github.com/indigolain/graphql_tag_pluck
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 2.6.0
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.4.1
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Plucks GraphQL document from Ruby codes
101
+ test_files: []