graphql_tag_pluck 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47adc95bd92376623769305b204563c4c4426aaaef907168f9808f68f188e664
4
- data.tar.gz: 339f872ef8f6b8b292f212cf5f4c81541b98d679bfd556f5f6bf32d47f4699c1
3
+ metadata.gz: 5fc879123c3218a9c9704d27de9f73d6457217f6170785b2ca4032db6c5ef9e5
4
+ data.tar.gz: f71ac80455fd5e311ce6ee64bf517d137fc1af1a2b85eefdb8d3c87c8291b1f4
5
5
  SHA512:
6
- metadata.gz: a4ba7fc5f68fc3b6588d33f175aff496e458f0f94dae6c3af167ac911aa85234eacfb047fbe88529998d0bce2497489cf19dc73cf9a5f47815466767ee11ea56
7
- data.tar.gz: 2eb339b83ccd461ad5cd9efe3428d21392fe2e358a8822e282daf9a3460dc75b7121ad4efcbccf3bc8d711c8b8daaf465d1dcf096a029df9a3f2115ff991733a
6
+ metadata.gz: b853d781cae40276c87ccfdc35e91a7390c651bedc478d4076d2bd7e86942d0554f77ddc593ee3af0307bc4e88c5ed6174f86695838129c69e5bbcd3ad250b07
7
+ data.tar.gz: b5c5f3f44f399e4bcedebfe4aba9673ea2d51e10481a0f9bbbf9607163c187c2a986d69071f3cf086ed0c65e41a92b22889adea3b0ac864fd54747ab08870631
data/README.md CHANGED
@@ -1,12 +1,48 @@
1
1
  # GraphqlTagPluck
2
2
 
3
- A gem for plucking GraphQL queries / mutations / fragments defined by heredocs inside files and exporting them to json file.
3
+ A gem for plucking GraphQL queries / mutations / fragments defined by heredocs inside `.rb` files and exporting them into a json file.
4
+
4
5
  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
 
6
7
  ```sh
7
8
  bundle exec rake graphql_tag_pluck:generate_graphql_operation_list
8
9
  ```
9
10
 
11
+ ## Usage
12
+
13
+ With a sample heredoc like the following inside a `.rb` file:
14
+
15
+ ```ruby
16
+ SAMPLE_QUERY = <<-GRAPHQL
17
+ query SampleQuery {
18
+ hoge
19
+ fuga {
20
+ piyo
21
+ }
22
+ }
23
+ GRAPHQL
24
+ ```
25
+
26
+ will output json file like: (following json content is formatted)
27
+
28
+ ```json
29
+ {
30
+ "SampleQuery": {
31
+ "name": "SampleQuery",
32
+ "source": "query SampleQuery {\n hoge\n fuga {\n piyo\n }\n}",
33
+ "type": "query"
34
+ }
35
+ }
36
+ ```
37
+
38
+ by executing
39
+
40
+ ```sh
41
+ bundle exec rake graphql_tag_pluck:generate_graphql_operation_list
42
+ ```
43
+
44
+ ## Configuration
45
+
10
46
  You can configure the following options by creating `.graphqltagpluckconfig.yaml` and specifying them inside.
11
47
 
12
48
  - graphql_heredoc_identifiers
@@ -21,15 +57,11 @@ You can configure the following options by creating `.graphqltagpluckconfig.yaml
21
57
 
22
58
  ## Installation
23
59
 
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
60
  Install the gem and add to the application's Gemfile by executing:
27
61
 
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
62
+ ```sh
63
+ $ bundle add graphql_tag_pluck
64
+ ```
33
65
 
34
66
  ## License
35
67
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphqlTagPluck
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -23,6 +23,7 @@ module GraphqlTagPluck
23
23
 
24
24
  def get_graphql_heredocs
25
25
  files = Dir.glob(GraphqlTagPluck.options[:file_glob_pattern])
26
+ unnamed_operation_count = 0
26
27
 
27
28
  {}.tap do |hash|
28
29
  files.each do |file|
@@ -33,7 +34,14 @@ module GraphqlTagPluck
33
34
  parsed_node_array.flatten.compact.each do |graphql_doc_string|
34
35
  parsed_graphql_doc_string = GraphQL.parse(graphql_doc_string)
35
36
  parsed_graphql_doc_string.definitions.each do |definition|
36
- hash[definition.name] = {
37
+ key = if definition.name.nil?
38
+ unnamed_operation_count += 1
39
+ "unnamed_operation_#{unnamed_operation_count}"
40
+ else
41
+ definition.name
42
+ end
43
+
44
+ hash[key] = {
37
45
  name: definition.name,
38
46
  source: definition.to_query_string,
39
47
  type: definition.instance_of?(GraphQL::Language::Nodes::FragmentDefinition) ? 'fragment' : definition.operation_type
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql_tag_pluck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - indigolain