dry-graphql 0.2.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: a01ec2992e9c7f3e3355c54790f266a7d2c1d6bfac2e3982ee9cfc7ec379fda0
4
+ data.tar.gz: cb298219a9bc9e0869cb114eb3c5eb7fc568c8d26d050e746edda7c69da7fa4a
5
+ SHA512:
6
+ metadata.gz: 5d07c44efcc2ce65ff7718a8c6161fce4e58f3499b0c6fd4d3f2bf9f86d4790ace571fa977d06426158776010e528b93b49525701c091621efbab9f732dcd19d
7
+ data.tar.gz: 8df3181149fe8258ebcd52d2cdca1c07f5eb30c8e33dd5b3353545a97a2bf7ae4c560d9db3890d0bd8aa4b85d35c0a5379ba9297fab372f55a8ac1e4306725a5
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ ---
2
+ inherit_from: .rubocop_todo.yml
3
+
4
+ AllCops:
5
+ UseCache: true
6
+ TargetRubyVersion: 2.5
7
+ Exclude:
8
+ - gemfiles/**/*
9
+
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - spec/**/*
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,44 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2019-05-09 23:30:53 -0400 using RuboCop version 0.59.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ Metrics/AbcSize:
11
+ Max: 41
12
+
13
+ # Offense count: 3
14
+ # Configuration parameters: CountComments, ExcludedMethods.
15
+ # ExcludedMethods: refine
16
+ Metrics/BlockLength:
17
+ Max: 114
18
+
19
+ # Offense count: 1
20
+ # Configuration parameters: CountComments.
21
+ Metrics/ClassLength:
22
+ Max: 146
23
+
24
+ # Offense count: 2
25
+ Metrics/CyclomaticComplexity:
26
+ Max: 14
27
+
28
+ # Offense count: 1
29
+ # Configuration parameters: CountComments, ExcludedMethods.
30
+ Metrics/MethodLength:
31
+ Max: 11
32
+
33
+ # Offense count: 1
34
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
35
+ # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
36
+ Naming/FileName:
37
+ Exclude:
38
+ - 'lib/dry-graphql.rb'
39
+
40
+ # Offense count: 19
41
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
42
+ # URISchemes: http, https
43
+ Metrics/LineLength:
44
+ Max: 102
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ gemfile:
6
+ - gemfiles/dry_struct_4.gemfile
7
+ - gemfiles/dry_struct_5.gemfile
8
+ script:
9
+ - bundle exec rubocop
10
+ - bundle exec rspec
11
+ rvm:
12
+ - 2.5.1
13
+ before_install: gem install bundler -v 1.16.5
data/Appraisals ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise 'dry-struct-4' do
4
+ gem 'dry-struct', '~> 0.4.0'
5
+ end
6
+
7
+ appraise 'dry-struct-5' do
8
+ gem 'dry-struct', '~> 0.5.0'
9
+ end
10
+
11
+ # vi: ft=ruby
@@ -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 i.kerseymer@gmail.com. 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,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # gem 'dry-struct'
8
+ gem 'graphql'
9
+
10
+ group :development, :test do
11
+ gem 'pry'
12
+ gem 'rubocop'
13
+ end
14
+
15
+ # Specify your gem's dependencies in dry-graphql.gemspec
16
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Ian Ker-Seymer
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,108 @@
1
+ # Dry::GraphQL
2
+ [![Build Status](https://travis-ci.org/adHawk/dry-graphql.svg?branch=master)](https://travis-ci.org/adHawk/dry-graphql)
3
+
4
+ `dry-graphql` makes [dry-types](https://dry-rb.org/gems/dry-types/) and
5
+ [dry-struct](https://dry-rb.org/gems/dry-types/) play nicely with GraphQL. It
6
+ adds a `graphql_type` method which will automatically generate a
7
+ [graphql-ruby](http://graphql-ruby.org/). This takes the manual work out of
8
+ maintaining multiple type definitions. Specify your `dry-type`, and re-use it
9
+ for GraphQL.
10
+
11
+ ## Usage
12
+
13
+ Here is an example of using it with `dry-struct`:
14
+
15
+ ```ruby
16
+ class User < Dry::Struct
17
+ module Types
18
+ include Dry::Types.module
19
+ end
20
+
21
+ attribute :name, Types::Strict::String.optional
22
+ attribute :age, Types::Coercible::Integer
23
+ attribute :middle_name, Types::Coercible::String
24
+ end
25
+
26
+ class UserType < User.graphql_type(only: [:name, :age])
27
+ # you can add other fields here if you want
28
+ end
29
+
30
+ class Query < GraphQL::Schema::Object
31
+ field :user, UserType, null: false
32
+ end
33
+
34
+ class Schema < GraphQL::Schema
35
+ query Query
36
+ end
37
+
38
+ puts schema.to_definition # =>
39
+ # type Query {
40
+ # user: User!
41
+ # }
42
+ #
43
+ # type User {
44
+ # age: Int!
45
+ # name: String
46
+ # }
47
+ end
48
+ ```
49
+
50
+ ### Usage with rom-sql
51
+
52
+ To add a `graphql_type` method to a `ROM::Relation`:
53
+
54
+
55
+ ```ruby
56
+ require 'dry/graphql/rom'
57
+
58
+ class Users < ROM::Relation[:sql]
59
+ extend Dry::GraphQL::ROM
60
+ end
61
+ ```
62
+
63
+ ## Installation
64
+
65
+ Add this line to your application's Gemfile:
66
+
67
+ ```ruby
68
+ gem 'dry-graphql'
69
+ ```
70
+
71
+ And then execute:
72
+
73
+ $ bundle
74
+
75
+ Or install it yourself as:
76
+
77
+ $ gem install dry-graphql
78
+
79
+
80
+ ## Development
81
+
82
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
83
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
84
+ prompt that will allow you to experiment.
85
+
86
+ To install this gem onto your local machine, run `bundle exec rake install`. To
87
+ release a new version, update the version number in `version.rb`, and then run
88
+ `bundle exec rake release`, which will create a git tag for the version, push
89
+ git commits and tags, and push the `.gem` file to
90
+ [rubygems.org](https://rubygems.org).
91
+
92
+ ## Contributing
93
+
94
+ Bug reports and pull requests are welcome on GitHub at
95
+ https://github.com/adhawk/dry-graphql. This project is intended to be a safe,
96
+ welcoming space for collaboration, and contributors are expected to adhere to
97
+ the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
98
+
99
+ ## License
100
+
101
+ The gem is available as open source under the terms of the [MIT
102
+ License](https://opensource.org/licenses/MIT).
103
+
104
+ ## Code of Conduct
105
+
106
+ Everyone interacting in the Dry::GraphQL project’s codebases, issue trackers,
107
+ chat rooms and mailing lists is expected to follow the [code of
108
+ conduct](https://github.com/adhawk/dry-graphql/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'dry/graphql'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'dry/graphql/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'dry-graphql'
9
+ spec.version = Dry::GraphQL::VERSION
10
+ spec.authors = ['Ian Ker-Seymer']
11
+ spec.email = ['i.kerseymer@gmail.com']
12
+
13
+ spec.summary = 'Integrate dry-types/dry-struct with graphql-ruby'
14
+ spec.description = 'Adds functionality to make dry-types/dry-struct play nicely with graphql-ruby'
15
+ spec.homepage = 'https://github.com/adhawk/dry-graphql'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ # if spec.respond_to?(:metadata)
21
+ # spec.metadata['allowed_push_host'] = 'https//rubygems.org'
22
+ # else
23
+ # raise 'RubyGems 2.0 or newer is required to protect against ' \
24
+ # 'public gem pushes.'
25
+ # end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ['lib']
35
+ spec.add_runtime_dependency 'dry-struct', '>= 0.4.0', '< 1.0.0'
36
+ spec.add_runtime_dependency 'graphql', '~> 1.8.0'
37
+
38
+ spec.add_development_dependency 'appraisal'
39
+ spec.add_development_dependency 'bundler', '~> 1.16'
40
+ spec.add_development_dependency 'rake', '~> 10.0'
41
+ spec.add_development_dependency 'rspec', '~> 3.0'
42
+ end
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "graphql"
6
+ gem "dry-struct", "~> 0.4.0"
7
+
8
+ group :development, :test do
9
+ gem "pry"
10
+ gem "rubocop"
11
+ end
12
+
13
+ gemspec path: "../"
@@ -0,0 +1,97 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ dry-graphql (0.1.0)
5
+ dry-struct (>= 0.4.0)
6
+ graphql (~> 1.8.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ appraisal (2.2.0)
12
+ bundler
13
+ rake
14
+ thor (>= 0.14.0)
15
+ ast (2.4.0)
16
+ coderay (1.1.2)
17
+ concurrent-ruby (1.0.5)
18
+ diff-lcs (1.3)
19
+ dry-configurable (0.7.0)
20
+ concurrent-ruby (~> 1.0)
21
+ dry-container (0.6.0)
22
+ concurrent-ruby (~> 1.0)
23
+ dry-configurable (~> 0.1, >= 0.1.3)
24
+ dry-core (0.4.7)
25
+ concurrent-ruby (~> 1.0)
26
+ dry-equalizer (0.2.1)
27
+ dry-inflector (0.1.2)
28
+ dry-logic (0.4.2)
29
+ dry-container (~> 0.2, >= 0.2.6)
30
+ dry-core (~> 0.2)
31
+ dry-equalizer (~> 0.2)
32
+ dry-struct (0.4.0)
33
+ dry-core (~> 0.4, >= 0.4.1)
34
+ dry-equalizer (~> 0.2)
35
+ dry-types (~> 0.12, >= 0.12.2)
36
+ ice_nine (~> 0.11)
37
+ dry-types (0.13.2)
38
+ concurrent-ruby (~> 1.0)
39
+ dry-container (~> 0.3)
40
+ dry-core (~> 0.4, >= 0.4.4)
41
+ dry-equalizer (~> 0.2)
42
+ dry-inflector (~> 0.1, >= 0.1.2)
43
+ dry-logic (~> 0.4, >= 0.4.2)
44
+ graphql (1.8.10)
45
+ ice_nine (0.11.2)
46
+ jaro_winkler (1.5.1)
47
+ method_source (0.9.0)
48
+ parallel (1.12.1)
49
+ parser (2.5.1.2)
50
+ ast (~> 2.4.0)
51
+ powerpack (0.1.2)
52
+ pry (0.11.3)
53
+ coderay (~> 1.1.0)
54
+ method_source (~> 0.9.0)
55
+ rainbow (3.0.0)
56
+ rake (10.5.0)
57
+ rspec (3.8.0)
58
+ rspec-core (~> 3.8.0)
59
+ rspec-expectations (~> 3.8.0)
60
+ rspec-mocks (~> 3.8.0)
61
+ rspec-core (3.8.0)
62
+ rspec-support (~> 3.8.0)
63
+ rspec-expectations (3.8.1)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.8.0)
66
+ rspec-mocks (3.8.0)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.8.0)
69
+ rspec-support (3.8.0)
70
+ rubocop (0.59.2)
71
+ jaro_winkler (~> 1.5.1)
72
+ parallel (~> 1.10)
73
+ parser (>= 2.5, != 2.5.1.1)
74
+ powerpack (~> 0.1)
75
+ rainbow (>= 2.2.2, < 4.0)
76
+ ruby-progressbar (~> 1.7)
77
+ unicode-display_width (~> 1.0, >= 1.0.1)
78
+ ruby-progressbar (1.10.0)
79
+ thor (0.20.0)
80
+ unicode-display_width (1.4.0)
81
+
82
+ PLATFORMS
83
+ ruby
84
+
85
+ DEPENDENCIES
86
+ appraisal
87
+ bundler (~> 1.16)
88
+ dry-graphql!
89
+ dry-struct (~> 0.4.0)
90
+ graphql
91
+ pry
92
+ rake (~> 10.0)
93
+ rspec (~> 3.0)
94
+ rubocop
95
+
96
+ BUNDLED WITH
97
+ 1.16.1
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "graphql"
6
+ gem "dry-struct", "~> 0.5.0"
7
+
8
+ group :development, :test do
9
+ gem "pry"
10
+ gem "rubocop"
11
+ end
12
+
13
+ gemspec path: "../"
@@ -0,0 +1,97 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ dry-graphql (0.1.0)
5
+ dry-struct (>= 0.4.0)
6
+ graphql (~> 1.8.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ appraisal (2.2.0)
12
+ bundler
13
+ rake
14
+ thor (>= 0.14.0)
15
+ ast (2.4.0)
16
+ coderay (1.1.2)
17
+ concurrent-ruby (1.0.5)
18
+ diff-lcs (1.3)
19
+ dry-configurable (0.7.0)
20
+ concurrent-ruby (~> 1.0)
21
+ dry-container (0.6.0)
22
+ concurrent-ruby (~> 1.0)
23
+ dry-configurable (~> 0.1, >= 0.1.3)
24
+ dry-core (0.4.7)
25
+ concurrent-ruby (~> 1.0)
26
+ dry-equalizer (0.2.1)
27
+ dry-inflector (0.1.2)
28
+ dry-logic (0.4.2)
29
+ dry-container (~> 0.2, >= 0.2.6)
30
+ dry-core (~> 0.2)
31
+ dry-equalizer (~> 0.2)
32
+ dry-struct (0.5.0)
33
+ dry-core (~> 0.4, >= 0.4.3)
34
+ dry-equalizer (~> 0.2)
35
+ dry-types (~> 0.13)
36
+ ice_nine (~> 0.11)
37
+ dry-types (0.13.2)
38
+ concurrent-ruby (~> 1.0)
39
+ dry-container (~> 0.3)
40
+ dry-core (~> 0.4, >= 0.4.4)
41
+ dry-equalizer (~> 0.2)
42
+ dry-inflector (~> 0.1, >= 0.1.2)
43
+ dry-logic (~> 0.4, >= 0.4.2)
44
+ graphql (1.8.10)
45
+ ice_nine (0.11.2)
46
+ jaro_winkler (1.5.1)
47
+ method_source (0.9.0)
48
+ parallel (1.12.1)
49
+ parser (2.5.1.2)
50
+ ast (~> 2.4.0)
51
+ powerpack (0.1.2)
52
+ pry (0.11.3)
53
+ coderay (~> 1.1.0)
54
+ method_source (~> 0.9.0)
55
+ rainbow (3.0.0)
56
+ rake (10.5.0)
57
+ rspec (3.8.0)
58
+ rspec-core (~> 3.8.0)
59
+ rspec-expectations (~> 3.8.0)
60
+ rspec-mocks (~> 3.8.0)
61
+ rspec-core (3.8.0)
62
+ rspec-support (~> 3.8.0)
63
+ rspec-expectations (3.8.1)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.8.0)
66
+ rspec-mocks (3.8.0)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.8.0)
69
+ rspec-support (3.8.0)
70
+ rubocop (0.59.2)
71
+ jaro_winkler (~> 1.5.1)
72
+ parallel (~> 1.10)
73
+ parser (>= 2.5, != 2.5.1.1)
74
+ powerpack (~> 0.1)
75
+ rainbow (>= 2.2.2, < 4.0)
76
+ ruby-progressbar (~> 1.7)
77
+ unicode-display_width (~> 1.0, >= 1.0.1)
78
+ ruby-progressbar (1.10.0)
79
+ thor (0.20.0)
80
+ unicode-display_width (1.4.0)
81
+
82
+ PLATFORMS
83
+ ruby
84
+
85
+ DEPENDENCIES
86
+ appraisal
87
+ bundler (~> 1.16)
88
+ dry-graphql!
89
+ dry-struct (~> 0.5.0)
90
+ graphql
91
+ pry
92
+ rake (~> 10.0)
93
+ rspec (~> 3.0)
94
+ rubocop
95
+
96
+ BUNDLED WITH
97
+ 1.16.1
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module GraphQL
5
+ # Base schema object
6
+ class BaseObject < ::GraphQL::Schema::Object
7
+ def self.map_from(*associated_classes)
8
+ associated_classes.each do |associated_class|
9
+ ::Dry::GraphQL.register_type_mapping(associated_class, self)
10
+ end
11
+ true
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module GraphQL
5
+ # Adds graphql_type to a rom relation
6
+ #
7
+ # @example
8
+ #
9
+ # require 'dry/graphql/rom'
10
+ #
11
+ # class Users < ROM::Relation[:sql]
12
+ # extend Dry::GraphQL::ROM
13
+ # end
14
+ module ROM
15
+ def graphql_type(opts = {})
16
+ return @graphql_type if @graphql_type
17
+
18
+ base_schema = schema.any?(&:read?) ? schema.to_output_hash : NOOP_OUTPUT_SCHEMA
19
+ type_name = Dry::Core::Inflector.singularize(name)
20
+ @graphql_type ||= Dry::GraphQL.from(base_schema, name: type_name, **opts)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,198 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'graphql'
4
+ require 'dry/graphql/types'
5
+ require 'dry/graphql/type_mappings'
6
+ require 'dry/graphql/base_object'
7
+ require 'dry/core/class_builder'
8
+
9
+ module Dry
10
+ module GraphQL
11
+ # Module for generated types
12
+ module GeneratedTypes
13
+ end
14
+
15
+ # Reduces a DRY type to a GraphQL type
16
+ class SchemaBuilder
17
+ attr_reader :field, :type, :options, :schema, :name, :parent
18
+
19
+ class TypeMappingError < StandardError; end
20
+ class NameGenerationError < StandardError; end
21
+
22
+ def initialize(name: nil, type: nil, schema: nil, parent: nil, options: {})
23
+ @name = name
24
+ @type = type
25
+ @schema = schema
26
+ @options = options
27
+ @parent = parent
28
+ end
29
+
30
+ def with(opts)
31
+ self.class.new({
32
+ name: @name, type: @type, schema: @schema, options: @options,
33
+ parent: self
34
+ }.merge(opts))
35
+ end
36
+
37
+ def reduce_with(*args)
38
+ with(*args).reduce
39
+ end
40
+
41
+ def graphql_type
42
+ reduce
43
+ end
44
+
45
+ def self.build_graphql_schema_class(name)
46
+ Dry::Core::ClassBuilder.new(
47
+ name: name,
48
+ parent: ::Dry::GraphQL::BaseObject,
49
+ namespace: Dry::GraphQL::GeneratedTypes
50
+ ).call
51
+ end
52
+
53
+ protected
54
+
55
+ # rubocop:disable Metrics/MethodLength
56
+ def reduce
57
+ case type
58
+ when specified_in_meta?
59
+ type.meta[:graphql_type]
60
+ when pkey_or_fkey?
61
+ ::GraphQL::Types::ID
62
+ when scalar?
63
+ TypeMappings.map_scalar type
64
+ when primitive?
65
+ TypeMappings.map_type(type.primitive)
66
+ when hash_schema?
67
+ map_hash type.options[:member_types]
68
+ when raw_hash_type?
69
+ # FIXME: this should be configurable
70
+ ::Dry::GraphQL::Types::JSON
71
+ when Dry::Types::Array::Member
72
+ map_array type
73
+ when ::Hash
74
+ map_hash type
75
+ when schema?
76
+ map_schema type
77
+ when ::Dry::Types::Hash
78
+ schema
79
+ when ::Dry::Types::Constrained, Dry::Types::Constructor
80
+ reduce_with type: type.type
81
+ when ::Dry::Types::Sum::Constrained, ::Dry::Types::Sum
82
+ reduce_with type: type.right
83
+ when ::Dry::Types::Definition
84
+ reduce_with type: type.primitive
85
+ else
86
+ raise_type_mapping_error(type)
87
+ end
88
+ end
89
+ # rubocop:enable Metrics/MethodLength
90
+
91
+ def raise_type_mapping_error(type)
92
+ raise TypeMappingError,
93
+ "Cannot map #{type}. Please make sure " \
94
+ "it is registered by calling:\n" \
95
+ "Dry::GraphQL.register_type_mapping #{type}, MyGraphQLType"
96
+ end
97
+
98
+ def primitive?
99
+ lambda do |type|
100
+ type.respond_to?(:primitive) && TypeMappings.scalar?(type.primitive)
101
+ rescue NoMethodError # when respond_to is incorrect (i.e. Dry::Types::Constructor)
102
+ false
103
+ end
104
+ end
105
+
106
+ def scalar?
107
+ TypeMappings.method(:scalar?)
108
+ end
109
+
110
+ def schema?
111
+ ->(type) { type.respond_to?(:schema) }
112
+ end
113
+
114
+ def hash_schema?
115
+ ->(type) { type.respond_to?(:options) && type.options.key?(:member_types) }
116
+ end
117
+
118
+ def specified_in_meta?
119
+ ->(type) { type.respond_to?(:meta) && type.meta.key?(:graphql_type) }
120
+ end
121
+
122
+ def raw_hash_type?
123
+ ->(type) { type.is_a?(Dry::Types::Hash) && !type.options.key(:member_types) }
124
+ end
125
+
126
+ def pkey_or_fkey?
127
+ ->(type) { type.respond_to?(:meta) && (type.meta[:primary_key] || type.meta[:foreign_key]) }
128
+ end
129
+
130
+ def map_hash(hash)
131
+ hash.each do |field_name, field_type|
132
+ next if skip?(field_name)
133
+
134
+ schema.field(
135
+ field_name,
136
+ with(name: field_name, type: field_type).reduce,
137
+ null: nullable?(field_type)
138
+ )
139
+ end
140
+ schema
141
+ end
142
+
143
+ def skip?(field_name)
144
+ return false unless options.key?(:only) || options.key?(:skip)
145
+
146
+ if options.key?(:only) && options.key?(:skip)
147
+ return InvalidOptionsError, 'Can only use :skip or :only, not both'
148
+ end
149
+
150
+ return options.fetch(:skip, []).include?(field_name.to_sym) if options.key?(:skip)
151
+
152
+ return !options.fetch(:only, []).include?(field_name.to_sym) if options.key?(:only)
153
+
154
+ false
155
+ end
156
+
157
+ def map_array(type)
158
+ member_type = type.options[:member]
159
+ member_graphql_type = with(type: member_type).reduce
160
+ [member_graphql_type]
161
+ end
162
+
163
+ def map_schema(type)
164
+ graphql_name = generate_name
165
+ graphql_schema = self.class.build_graphql_schema_class(graphql_name)
166
+ graphql_schema.graphql_name
167
+ type_to_map = if type.respond_to?(:schema) && type.method(:schema).arity.zero?
168
+ type.schema
169
+ else
170
+ type.type
171
+ end
172
+ opts = { name: graphql_name, type: type_to_map, schema: graphql_schema, options: options }
173
+ SchemaBuilder.new(opts).reduce
174
+ end
175
+
176
+ def generate_name
177
+ name_tree = []
178
+ cursor = self
179
+ loop do
180
+ break if cursor.nil?
181
+
182
+ sanitized_name = cursor.name.to_s.capitalize.gsub('::', '__')
183
+ name_tree.unshift(sanitized_name)
184
+ cursor = cursor.parent
185
+ end
186
+ name_tree.join('__')
187
+ rescue StandardError => e
188
+ raise NameGenerationError, "Could not generate_name for #{type}: #{e.message}"
189
+ end
190
+
191
+ def nullable?(type)
192
+ return false unless type.respond_to?(:left)
193
+
194
+ type.left.type.primitive == NilClass
195
+ end
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'graphql/types'
4
+ require 'dry/core/class_attributes'
5
+
6
+ module Dry
7
+ module GraphQL
8
+ # Class to Ruby types to GraphQL types
9
+ class TypeMappings
10
+ class UnmappableTypeError < StandardError; end
11
+
12
+ extend Dry::Core::ClassAttributes
13
+
14
+ defines :scalar_mappings
15
+ scalar_mappings(
16
+ ::String => ::GraphQL::Types::String,
17
+ ::Integer => ::GraphQL::Types::Int,
18
+ ::TrueClass => ::GraphQL::Types::Boolean,
19
+ ::FalseClass => ::GraphQL::Types::Boolean,
20
+ ::Float => ::GraphQL::Types::Float,
21
+ ::Date => ::GraphQL::Types::ISO8601DateTime,
22
+ ::Time => ::GraphQL::Types::ISO8601DateTime
23
+ )
24
+
25
+ defines :registry
26
+ registry(scalar_mappings)
27
+
28
+ class << self
29
+ def map_type(type, mappings = registry)
30
+ mappings.fetch(type) do
31
+ raise UnmappableTypeError,
32
+ "Cannot map #{type}. Please make sure " \
33
+ "it is registered by calling:\n" \
34
+ "Dry::GraphQL.register_type_mapping #{type}, MyGraphQLType"
35
+ end
36
+ end
37
+
38
+ def map_scalar(type)
39
+ map_type(type, scalar_mappings)
40
+ end
41
+
42
+ def scalar?(type)
43
+ keys = scalar_mappings.keys
44
+ keys.include?(type)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module GraphQL
5
+ module Types
6
+ # JSON type, needed for Dry::Types::Hash currently
7
+ class JSON < ::GraphQL::Schema::Scalar
8
+ description 'A valid JSON document, transported as a string'
9
+
10
+ def self.coerce_input(str, _ctx)
11
+ JSON.parse(str)
12
+ end
13
+
14
+ def self.coerce_result(obj, _ctx)
15
+ JSON.dump(obj)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module GraphQL
5
+ VERSION = '0.2.0'
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/graphql/version'
4
+ require 'dry-struct'
5
+ require 'dry/graphql/schema_builder'
6
+
7
+ module Dry
8
+ # Module containing GraphQL enhancements
9
+ module GraphQL
10
+ # Extends Dry::Struct functionality
11
+ module Struct
12
+ def graphql_type(options = {})
13
+ return @graphql_type if @graphql_type
14
+
15
+ graphql_name = name.to_s.gsub('::', '__')
16
+ graphql_schema = SchemaBuilder.build_graphql_schema_class(name)
17
+ graphql_schema.graphql_name(name)
18
+ opts = { name: graphql_name, type: schema, schema: graphql_schema, options: options }
19
+ @graphql_type ||= SchemaBuilder.new(opts).graphql_type
20
+ end
21
+ end
22
+
23
+ class << self
24
+ def from(type, name:, **opts)
25
+ SchemaBuilder.new(name: name, type: type, options: opts).graphql_type
26
+ end
27
+
28
+ def register_type_mapping(input_type, output_type)
29
+ TypeMappings.registry.merge!(input_type => output_type)
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ Dry::Struct.extend(Dry::GraphQL::Struct)
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/graphql'
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dry-graphql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Ian Ker-Seymer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-struct
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.4.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: graphql
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 1.8.0
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 1.8.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: appraisal
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: bundler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.16'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.16'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '10.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '10.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.0'
103
+ description: Adds functionality to make dry-types/dry-struct play nicely with graphql-ruby
104
+ email:
105
+ - i.kerseymer@gmail.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - ".gitignore"
111
+ - ".rspec"
112
+ - ".rubocop.yml"
113
+ - ".rubocop_todo.yml"
114
+ - ".travis.yml"
115
+ - Appraisals
116
+ - CODE_OF_CONDUCT.md
117
+ - Gemfile
118
+ - LICENSE.txt
119
+ - README.md
120
+ - Rakefile
121
+ - bin/console
122
+ - bin/setup
123
+ - dry-graphql.gemspec
124
+ - gemfiles/.bundle/config
125
+ - gemfiles/dry_struct_4.gemfile
126
+ - gemfiles/dry_struct_4.gemfile.lock
127
+ - gemfiles/dry_struct_5.gemfile
128
+ - gemfiles/dry_struct_5.gemfile.lock
129
+ - lib/dry-graphql.rb
130
+ - lib/dry/graphql.rb
131
+ - lib/dry/graphql/base_object.rb
132
+ - lib/dry/graphql/rom.rb
133
+ - lib/dry/graphql/schema_builder.rb
134
+ - lib/dry/graphql/type_mappings.rb
135
+ - lib/dry/graphql/types.rb
136
+ - lib/dry/graphql/version.rb
137
+ homepage: https://github.com/adhawk/dry-graphql
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubygems_version: 3.0.3
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Integrate dry-types/dry-struct with graphql-ruby
160
+ test_files: []