graphiti_graphql 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/htmldiff ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'htmldiff' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("diff-lcs", "htmldiff")
data/bin/ldiff ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'ldiff' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("diff-lcs", "ldiff")
data/bin/pry ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'pry' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("pry", "pry")
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/rubocop ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rubocop", "rubocop")
data/bin/ruby-parse ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'ruby-parse' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("parser", "ruby-parse")
data/bin/ruby-rewrite ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'ruby-rewrite' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("parser", "ruby-rewrite")
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
data/bin/standardrb ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'standardrb' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("standard", "standardrb")
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ GraphitiGraphQL::Engine.routes.draw do
2
+ # Default json so our error handler takes effect
3
+ scope defaults: {format: :json} do
4
+ post "/" => "execution#execute"
5
+ end
6
+ end
@@ -0,0 +1,45 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "graphiti_graphql/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "graphiti_graphql"
7
+ spec.version = GraphitiGraphQL::VERSION
8
+ spec.authors = ["Lee Richmond"]
9
+ spec.email = ["lrichmond1@bloomberg.net"]
10
+
11
+ spec.summary = "GraphQL support for Graphiti"
12
+ spec.description = "GraphQL support for Graphiti"
13
+ spec.homepage = "https://www.graphiti.dev"
14
+
15
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
19
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "activesupport", ">= 4.1"
31
+ spec.add_dependency "graphql", "~> 1.12"
32
+
33
+ spec.add_development_dependency "pry"
34
+ spec.add_development_dependency "pry-byebug"
35
+ spec.add_development_dependency "graphql", "~> 1.12"
36
+ spec.add_development_dependency "graphiti_spec_helpers"
37
+ spec.add_development_dependency "activemodel", ">= 4.1"
38
+ spec.add_development_dependency "bundler", "~> 2.0"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ spec.add_development_dependency "standardrb"
42
+
43
+ spec.add_development_dependency "apollo-federation", "~> 1.1"
44
+ spec.add_development_dependency "graphql-batch", "~> 0.4"
45
+ end
@@ -0,0 +1,71 @@
1
+ require "active_support/core_ext/object/json"
2
+
3
+ require "graphiti_graphql/version"
4
+ require "graphiti_graphql/graphiti_schema/wrapper"
5
+ require "graphiti_graphql/graphiti_schema/sideload"
6
+ require "graphiti_graphql/graphiti_schema/resource"
7
+ require "graphiti_graphql/errors"
8
+ require "graphiti_graphql/schema"
9
+ require "graphiti_graphql/runner"
10
+ require "graphiti_graphql/util"
11
+
12
+ Graphiti.class_eval do
13
+ class << self
14
+ attr_writer :graphql_schema
15
+ end
16
+
17
+ # TODO probably move these off of Graphiti
18
+ def self.gql(query, variables)
19
+ runner = ::GraphitiGraphQL::Runner.new
20
+ runner.execute(query, variables, graphql_schema.schema)
21
+ end
22
+
23
+ def self.graphql_schema
24
+ @graphql_schema ||= GraphitiGraphQL::Schema.generate
25
+ end
26
+
27
+ def self.graphql_schema?
28
+ !!@graphql_schema
29
+ end
30
+
31
+ def self.graphql_schema!(entrypoint_resources = nil)
32
+ @graphql_schema = GraphitiGraphQL::Schema.generate(entrypoint_resources)
33
+ end
34
+ end
35
+
36
+ module GraphitiGraphQL
37
+ class Error < StandardError; end
38
+
39
+ class Configuration
40
+ attr_accessor :schema_reloading
41
+
42
+ def initialize
43
+ self.schema_reloading = true
44
+ end
45
+ end
46
+
47
+ class << self
48
+ attr_accessor :schema_class
49
+ end
50
+
51
+ def self.config
52
+ @config ||= Configuration.new
53
+ end
54
+
55
+ def self.define_context(&blk)
56
+ @define_context = blk
57
+ end
58
+
59
+ def self.get_context
60
+ obj = Graphiti.context[:object]
61
+ if @define_context
62
+ @define_context.call(obj)
63
+ else
64
+ {object: obj}
65
+ end
66
+ end
67
+ end
68
+
69
+ if defined?(::Rails)
70
+ require "graphiti_graphql/engine"
71
+ end
@@ -0,0 +1,89 @@
1
+ if ActiveSupport::Inflector.method(:inflections).arity == 0
2
+ # Rails 3 does not take a language in inflections.
3
+ ActiveSupport::Inflector.inflections do |inflect|
4
+ inflect.acronym("GraphitiGraphQL")
5
+ end
6
+ else
7
+ ActiveSupport::Inflector.inflections(:en) do |inflect|
8
+ inflect.acronym("GraphitiGraphQL")
9
+ end
10
+ end
11
+
12
+ module GraphitiGraphQL
13
+ class Engine < ::Rails::Engine
14
+ isolate_namespace GraphitiGraphQL
15
+
16
+ # Ensure error handling kicks in
17
+ # Corresponding default in config/routes.rb
18
+ config.graphiti.handled_exception_formats += [:json]
19
+
20
+ def self.reloader_class
21
+ case Rails::VERSION::MAJOR
22
+ when 4 then ActionDispatch::Reloader
23
+ when 5 then ActiveSupport::Reloader
24
+ when 6 then ::Rails.application.reloader
25
+ end
26
+ end
27
+
28
+ # In dev mode, resource classes are reloaded, and the new classes
29
+ # don't match what's in Graphiti.resources. Make sure everything is
30
+ # the most recent available.
31
+ # Really this belongs in graphiti-rails but keeping isolated for now
32
+ initializer "graphiti_graphql.reload_resources" do |app|
33
+ ::GraphitiGraphQL::Engine.reloader_class.to_prepare do
34
+ resources = []
35
+ Graphiti.resources.each do |resource|
36
+ next unless resource.name # remove
37
+ latest_resource = if (latest = resource.name.safe_constantize)
38
+ latest
39
+ else
40
+ resource
41
+ end
42
+
43
+ unless resources.find { |res| res.name == resource.name }
44
+ resources << latest_resource
45
+ end
46
+ end
47
+ Graphiti.instance_variable_set(:@resources, resources)
48
+ end
49
+ end
50
+
51
+ # We store a list of all federated relationships
52
+ # Clear that list when classes are cleared so we don't keep appending
53
+ initializer "graphiti_graphql.clear_federation" do |app|
54
+ GraphitiGraphQL::Engine.reloader_class.after_class_unload do
55
+ GraphitiGraphQL::Federation.clear!
56
+ end
57
+ end
58
+
59
+ initializer "graphiti_graphql.schema_reloading" do |app|
60
+ # Only reload the schema if we ask for it
61
+ # Some may want to avoid the performance penalty
62
+ if GraphitiGraphQL.config.schema_reloading
63
+ GraphitiGraphQL::Engine.reloader_class.to_prepare do
64
+ # We want to reload the schema when classes change
65
+ # But this way, you only pay the cost (time) when the GraphQL endpoint
66
+ # is actually hit
67
+ if Graphiti.graphql_schema?
68
+ Graphiti.graphql_schema = nil
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ initializer "graphiti_graphql.define_controller" do
75
+ # rubocop:disable Lint/ConstantDefinitionInBlock(Standard)
76
+ class GraphitiGraphQL::ExecutionController < ::ApplicationController
77
+ register_exception Graphiti::Errors::UnreadableAttribute, message: true
78
+ def execute
79
+ params = request.params # avoid strong_parameters
80
+ render json: Graphiti.gql(params[:query], params[:variables])
81
+ end
82
+ end
83
+ end
84
+
85
+ initializer "graphiti_graphql.federation" do
86
+ GraphitiGraphQL::Federation.setup!
87
+ end
88
+ end
89
+ end