shared-arguments 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3e10f487e896de7b6f8be61bb2a9674a2523cc04
4
+ data.tar.gz: 5c4bd2a1e0609f9022bc01764994ef74bf2e60f2
5
+ SHA512:
6
+ metadata.gz: 747e521e6ec520dddebcfc3204308170d57f04e1dccce43c4568f546e3bac131f68b3aba4cb34a0a92f905a2489be37e9e70e5d43bca39f76243ba7a8b2bbacd
7
+ data.tar.gz: 4fedee8bddcdf9b1b9f3c9e1435d61342b32b81e629c85631fcd7965a9a6cffe9dc387794a15becdcd80184823a291cbbc4cdca09208f35dbb091dfa8c332b3c
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4
5
+ before_install:
6
+ - gem update --system
7
+ - gem --version
8
+ rspec:
9
+ - bundle exec rspec
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at robert.pawlas@daftcode.pl. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+ ruby '~> 2.4'
3
+
4
+ gemspec
5
+
6
+ gem 'graphql'
7
+
8
+ group :test do
9
+ gem 'rspec'
10
+ gem 'rake'
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ shared-arguments (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ graphql (1.6.4)
11
+ rake (10.5.0)
12
+ rspec (3.5.0)
13
+ rspec-core (~> 3.5.0)
14
+ rspec-expectations (~> 3.5.0)
15
+ rspec-mocks (~> 3.5.0)
16
+ rspec-core (3.5.4)
17
+ rspec-support (~> 3.5.0)
18
+ rspec-expectations (3.5.0)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.5.0)
21
+ rspec-mocks (3.5.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.5.0)
24
+ rspec-support (3.5.0)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.14)
31
+ graphql
32
+ rake
33
+ rspec
34
+ shared-arguments!
35
+
36
+ RUBY VERSION
37
+ ruby 2.4.1p111
38
+
39
+ BUNDLED WITH
40
+ 1.15.4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Robert
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # shared-arguments
2
+
3
+ [![Build Status](https://travis-ci.org/hedselu/shared-arguments.svg?branch=master)](https://travis-ci.org/hedselu/shared-arguments)
4
+
5
+ Ruby gem for GraphQL arguments sharing within fields
6
+
7
+ **Sponsored by**
8
+ <br>
9
+ <br>
10
+ <a href="https:///www.indoorway.com/" target="_blank" rel="noopener noreferrer">
11
+ <img src="images/indoorway_logo.png" height="58" width="170" alt="Sponsored by Indoorway" style="max-width:100%;">
12
+ </a>
13
+
14
+ ## Contents
15
+ <!-- Table of contents generated generated by http://tableofcontent.eu -->
16
+ - [Description](#description)
17
+ - [Installation](#installation)
18
+ - [Setup](#setup)
19
+ - [Sample use case](#sample-use-case)
20
+
21
+ ## Description
22
+
23
+ Sometimes you want to use the same arguments for multiple fields in custom object type.
24
+ To avoid repeating those declarations and DRY-up your schema, I introduce you shared_arguments field.
25
+
26
+ This gem is mostly usable when you have:
27
+ - many fields with few repeating arguments
28
+ - few fields with many repeating arguments
29
+ - many fields with many repeating arguments
30
+
31
+ ## Installation
32
+
33
+ `gem install shared-arguments`
34
+
35
+ ## Setup
36
+
37
+ Include SharedArguments in your schema
38
+
39
+ ```ruby
40
+ #graphql/your_schema.rb
41
+
42
+ YourSchema = GraphQL::Schema.define do
43
+ use GraphQL::SharedArguments.new
44
+ end
45
+ ```
46
+
47
+ ## Sample use case
48
+
49
+ ```ruby
50
+ #graphql/types/analytics_type.rb
51
+
52
+ Types::AnalyticsType = GraphQL::ObjectType.define do
53
+ name 'Analytics'
54
+
55
+ field :invoices, types.[Types::Invoice] do
56
+ argument :from, !Types::DateType
57
+ argument :to, !Types::DateType
58
+ argument :companyID, types.ID
59
+ end
60
+
61
+ field :registeredUsers, types.[Types::User] do
62
+ argument :from, !Types::DateType
63
+ argument :to, !Types::DateType
64
+ argument :companyID, types.ID
65
+ end
66
+
67
+ field :downloadsAmount, types.Int do
68
+ argument :from, !Types::DateType
69
+ argument :to, !Types::DateType
70
+ argument :userAmount, types.ID
71
+ end
72
+ end
73
+ ```
74
+
75
+ This can be shortened like in below example
76
+
77
+ ```ruby
78
+ #graphql/types/analytics_type.rb
79
+
80
+ Types::AnalyticsType = GraphQL::ObjectType.define do
81
+ name 'Analytics'
82
+
83
+ field :invoices, types.[Types::Invoice]
84
+
85
+ field :registeredUsers, types.[Types::User]
86
+
87
+ field :downloadsAmount, types.Int do
88
+ argument :userAmount, types.ID
89
+ end
90
+
91
+ shared_arguments do
92
+ argument :from, !Types::DateType
93
+ argument :to, !Types::DateType
94
+ end
95
+
96
+ shared_arguments except: %i(downloadsAmount) do
97
+ argument :companyID, types.ID
98
+ end
99
+ end
100
+ ```
101
+
102
+ `shared_arguments` field takes both `except` and `only` keyword with array of symbols so you can omit or select specified fields.
103
+
104
+ Any contributions/suggestions/opened issues are welcomed.
105
+
106
+ License: MIT
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
Binary file
@@ -0,0 +1,26 @@
1
+ require 'graphql'
2
+ require 'graphql/shared_arguments/version'
3
+ require 'graphql/shared_arguments/injector'
4
+ require 'graphql/shared_arguments/define/assign_shared_arguments'
5
+
6
+ GraphQL::ObjectType.accepts_definitions(shared_arguments: GraphQL::SharedArguments::Define::AssignSharedArguments)
7
+
8
+ module GraphQL
9
+ class SharedArguments
10
+ include ::GraphQL::Define::InstanceDefinable
11
+
12
+ accepts_definitions :arguments,
13
+ :filter,
14
+ argument: ::GraphQL::Define::AssignArgument
15
+
16
+ ensure_defined :arguments, :filter
17
+ attr_accessor :arguments, :filter
18
+
19
+ def use(_schema_definition); end
20
+
21
+ def initialize
22
+ @filter = nil
23
+ @arguments = {}
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ module GraphQL
2
+ class SharedArguments
3
+ module Define
4
+ module AssignSharedArguments
5
+ def self.call(target, filter = {}, &block)
6
+ shared = GraphQL::SharedArguments.define(filter: filter, &block)
7
+ shared.define
8
+ GraphQL::SharedArguments::Injector.new(target, filter, shared.arguments).inject
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ module GraphQL
2
+ class SharedArguments
3
+ class Injector
4
+ def initialize(object_definition, filter, new_arguments)
5
+ @object_fields = object_definition.fields
6
+ @filter_type = filter.keys.first
7
+ @filter_fields = filter.values.first
8
+ @new_arguments = new_arguments
9
+ end
10
+
11
+ def only
12
+ object_fields.select { |k, _v| filter_fields.include?(k.to_sym) }
13
+ end
14
+
15
+ def except
16
+ object_fields.reject { |k, _v| filter_fields.include?(k.to_sym) }
17
+ end
18
+
19
+ def inject
20
+ @selected_fields = object_fields if filter_fields.nil? && filter_type.nil?
21
+ @selected_fields ||= send(filter_type)
22
+
23
+ selected_fields.transform_values do |field|
24
+ field.arguments.merge!(new_arguments)
25
+ end
26
+
27
+ object_fields.merge!(selected_fields)
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :object_fields, :selected_fields,
33
+ :filter_type, :filter_fields, :new_arguments
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ module GraphQL
2
+ class SharedArguments
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'graphql/shared_arguments/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'shared-arguments'
8
+ spec.version = GraphQL::SharedArguments::VERSION
9
+ spec.authors = ['Robert Pawlas']
10
+ spec.email = ['robert.pawlas@indoorway.com']
11
+
12
+ spec.summary = 'This gem allows you to share arguments between multiple fields while using graphql.'
13
+ spec.homepage = 'http://indoorway.com'
14
+ spec.license = 'MIT'
15
+
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
+ else
19
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
20
+ end
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
23
+ f.match(%r{^(test|spec|features)/})
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.14'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shared-arguments
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert Pawlas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - robert.pawlas@indoorway.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - images/indoorway_logo.png
72
+ - lib/graphql/shared_arguments.rb
73
+ - lib/graphql/shared_arguments/define/assign_shared_arguments.rb
74
+ - lib/graphql/shared_arguments/injector.rb
75
+ - lib/graphql/shared_arguments/version.rb
76
+ - shared-arguments.gemspec
77
+ homepage: http://indoorway.com
78
+ licenses:
79
+ - MIT
80
+ metadata:
81
+ allowed_push_host: https://rubygems.org
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: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.6.12
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: This gem allows you to share arguments between multiple fields while using
102
+ graphql.
103
+ test_files: []