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 +4 -4
- data/README.md +40 -8
- data/lib/graphql_tag_pluck/version.rb +1 -1
- data/lib/graphql_tag_pluck.rb +9 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fc879123c3218a9c9704d27de9f73d6457217f6170785b2ca4032db6c5ef9e5
|
4
|
+
data.tar.gz: f71ac80455fd5e311ce6ee64bf517d137fc1af1a2b85eefdb8d3c87c8291b1f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
29
|
-
|
30
|
-
|
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
|
|
data/lib/graphql_tag_pluck.rb
CHANGED
@@ -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
|
-
|
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
|