graphql-client 0.19.0 → 0.23.0

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: 3d469dea9c19c2b7b70f57554d66dab3374c496ef09bc013d9464509faac1243
4
- data.tar.gz: 7fdc9c16119e205cc1e200ee4fc5d882776bbd94c1294dc075963428d7d9f7e4
3
+ metadata.gz: 9ab40176a982910f10885b2c56a3d3ad867937ee4f824a4af06e75993236f1f0
4
+ data.tar.gz: 291c8ed2700b79bf5b41c2f799899dac7316d000b04e9cdeaae87cea0519e411
5
5
  SHA512:
6
- metadata.gz: 51ad31a0fd1faf1275037177e7b22f29f597ab9c03868831422de07f563a1c2911a32372832f45053c2430648a267067a721b66df5697fbc1e8735fefddf78b1
7
- data.tar.gz: 6162d16ba9cefdd82356c89fd799744bcb0777716c0a379c403f519c4aa5fb1c1d2a0a15955852f31d76326fcb6ceebb24fc861c85d211078e5b492bbbc95e0f
6
+ metadata.gz: 8a5a4cc5b341c302c1c2b20a12d10b59907a34ca9d50871e1e48c2984dbdf8562eb40eab123f6474eb96024ca6eeaa08f4ebf3c043dacb0e46f3211a3c00b921
7
+ data.tar.gz: 6cba9520177116c4d332578bee01f98a42adff2cba51ca123f7083a6980826725db7f090fcd8c37debdb3c654b7cac4b27b21e7f1f86d6a76b4e8676340d8f08
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # graphql-client [![Gem Version](https://badge.fury.io/rb/graphql-client.svg)](https://badge.fury.io/rb/graphql-client) [![CI](https://github.com/github/graphql-client/workflows/CI/badge.svg)](https://github.com/github/graphql-client/actions?query=workflow)
1
+ # graphql-client [![Gem Version](https://badge.fury.io/rb/graphql-client.svg)](https://badge.fury.io/rb/graphql-client) [![CI](https://github.com/github-community-projects/graphql-client/workflows/CI/badge.svg)](https://github.com/github-community-projects/graphql-client/actions?query=workflow)
2
2
 
3
3
  GraphQL Client is a Ruby library for declaring, composing and executing GraphQL queries.
4
4
 
@@ -26,7 +26,7 @@ module GraphQL
26
26
  return yield if Thread.current[:query_result_caller_location_ignore]
27
27
 
28
28
  if (location.path != path) && !(WHITELISTED_GEM_NAMES.any? { |g| location.path.include?("gems/#{g}") })
29
- error = NonCollocatedCallerError.new("#{method} was called outside of '#{path}' https://git.io/v1syX")
29
+ error = NonCollocatedCallerError.new("#{method} was called outside of '#{path}' https://github.com/github-community-projects/graphql-client/blob/master/guides/collocated-call-sites.md")
30
30
  error.set_backtrace(caller(2))
31
31
  raise error
32
32
  end
@@ -21,7 +21,7 @@ module GraphQL
21
21
  errors.each do |error|
22
22
  path = ["data"]
23
23
  current = data
24
- error.fetch("path", []).each do |key|
24
+ error["path"].to_a.each do |key|
25
25
  break unless current
26
26
  path << key
27
27
  current = current[key]
@@ -16,11 +16,18 @@ module GraphQL
16
16
  # GraphQL::Client::LogSubscriber.attach_to :graphql
17
17
  #
18
18
  class LogSubscriber < ActiveSupport::LogSubscriber
19
+ SHOULD_USE_KWARGS = private_instance_methods.include?(:mode_from)
20
+
19
21
  def query(event)
20
22
  logger.info do
21
23
  name = event.payload[:operation_name].gsub("__", "::")
22
24
  type = event.payload[:operation_type].upcase
23
- color("#{name} #{type} (#{event.duration.round(1)}ms)", nil, true)
25
+
26
+ if SHOULD_USE_KWARGS
27
+ color("#{name} #{type} (#{event.duration.round(1)}ms)", nil, bold: true)
28
+ else
29
+ color("#{name} #{type} (#{event.duration.round(1)}ms)", nil, true)
30
+ end
24
31
  end
25
32
 
26
33
  logger.debug do
@@ -32,7 +39,12 @@ module GraphQL
32
39
  logger.error do
33
40
  name = event.payload[:operation_name].gsub("__", "::")
34
41
  message = event.payload[:message]
35
- color("#{name} ERROR: #{message}", nil, true)
42
+
43
+ if SHOULD_USE_KWARGS
44
+ color("#{name} ERROR: #{message}", nil, bold: true)
45
+ else
46
+ color("#{name} ERROR: #{message}", nil, true)
47
+ end
36
48
  end
37
49
  end
38
50
  end
@@ -12,6 +12,7 @@ module GraphQL
12
12
  # Returns Hash.
13
13
  attr_reader :original_hash
14
14
  alias_method :to_h, :original_hash
15
+ alias_method :to_hash, :original_hash
15
16
 
16
17
  # Public: Wrapped ObjectType of data returned from the server.
17
18
  #
@@ -16,6 +16,10 @@ module GraphQL
16
16
  @enum = enum
17
17
  end
18
18
 
19
+ def unknown_enum_value?
20
+ false
21
+ end
22
+
19
23
  def respond_to_missing?(method_name, include_private = false)
20
24
  if method_name[-1] == "?" && @enum.include?(method_name[0..-2])
21
25
  true
@@ -37,6 +41,12 @@ module GraphQL
37
41
  end
38
42
  end
39
43
 
44
+ class UnexpectedEnumValue < String
45
+ def unknown_enum_value?
46
+ true
47
+ end
48
+ end
49
+
40
50
  # Internal: Construct enum wrapper from another GraphQL::EnumType.
41
51
  #
42
52
  # type - GraphQL::EnumType instance
@@ -78,8 +88,13 @@ module GraphQL
78
88
  def cast(value, _errors = nil)
79
89
  case value
80
90
  when String
81
- raise Error, "unexpected enum value #{value}" unless @values.key?(value)
82
- @values[value]
91
+ if @values.key?(value)
92
+ @values[value]
93
+ elsif schema_module.raise_on_unknown_enum_value
94
+ raise Error, "unexpected enum value #{value}"
95
+ else
96
+ UnexpectedEnumValue.new(value).freeze
97
+ end
83
98
  when NilClass
84
99
  value
85
100
  else
@@ -3,7 +3,6 @@ require "active_support/inflector"
3
3
  require "graphql/client/error"
4
4
  require "graphql/client/errors"
5
5
  require "graphql/client/schema/base_type"
6
- require "graphql/client/schema/possible_types"
7
6
 
8
7
  module GraphQL
9
8
  class Client
@@ -192,6 +191,7 @@ module GraphQL
192
191
  def to_h
193
192
  @data
194
193
  end
194
+ alias :to_hash :to_h
195
195
 
196
196
  def _definer
197
197
  @definer
@@ -255,13 +255,13 @@ module GraphQL
255
255
  end
256
256
 
257
257
  unless field
258
- raise UnimplementedFieldError, "undefined field `#{e.name}' on #{type.graphql_name} type. https://git.io/v1y3m"
258
+ raise UnimplementedFieldError, "undefined field `#{e.name}' on #{type.graphql_name} type. https://github.com/github-community-projects/graphql-client/blob/master/guides/unimplemented-field-error.md"
259
259
  end
260
260
 
261
261
  if @data.key?(field.name)
262
- raise ImplicitlyFetchedFieldError, "implicitly fetched field `#{field.name}' on #{type} type. https://git.io/v1yGL"
262
+ raise ImplicitlyFetchedFieldError, "implicitly fetched field `#{field.name}' on #{type} type. https://github.com/github-community-projects/graphql-client/blob/master/guides/implicitly-fetched-field-error.md"
263
263
  else
264
- raise UnfetchedFieldError, "unfetched field `#{field.name}' on #{type} type. https://git.io/v1y3U"
264
+ raise UnfetchedFieldError, "unfetched field `#{field.name}' on #{type} type. https://github.com/github-community-projects/graphql-client/blob/master/guides/unfetched-field-error.md"
265
265
  end
266
266
  end
267
267
  end
@@ -43,7 +43,7 @@ module GraphQL
43
43
  def set_class(type_name, klass)
44
44
  class_name = normalize_type_name(type_name)
45
45
 
46
- if constants.include?(class_name.to_sym)
46
+ if const_defined?(class_name, false)
47
47
  raise ArgumentError,
48
48
  "Can't define #{class_name} to represent type #{type_name} " \
49
49
  "because it's already defined"
@@ -66,9 +66,10 @@ module GraphQL
66
66
  end
67
67
  end
68
68
 
69
- def self.generate(schema)
69
+ def self.generate(schema, raise_on_unknown_enum_value: true)
70
70
  mod = Module.new
71
71
  mod.extend ClassMethods
72
+ mod.define_singleton_method(:raise_on_unknown_enum_value) { raise_on_unknown_enum_value }
72
73
 
73
74
  cache = {}
74
75
  schema.types.each do |name, type|
@@ -91,7 +91,7 @@ module GraphQL
91
91
  result
92
92
  end
93
93
 
94
- def initialize(schema:, execute: nil, enforce_collocated_callers: false)
94
+ def initialize(schema:, execute: nil, enforce_collocated_callers: false, raise_on_unknown_enum_value: true)
95
95
  @schema = self.class.load_schema(schema)
96
96
  @execute = execute
97
97
  @document = GraphQL::Language::Nodes::Document.new(definitions: [])
@@ -100,8 +100,13 @@ module GraphQL
100
100
  @enforce_collocated_callers = enforce_collocated_callers
101
101
  if schema.is_a?(Class)
102
102
  @possible_types = schema.possible_types
103
+ key, _types = @possible_types.first
104
+ # GraphQL-Ruby 2.3.5+ has classes here instead of strings
105
+ if key.is_a?(Module)
106
+ @possible_types = @possible_types.transform_keys(&:graphql_name)
107
+ end
103
108
  end
104
- @types = Schema.generate(@schema)
109
+ @types = Schema.generate(@schema, raise_on_unknown_enum_value: raise_on_unknown_enum_value)
105
110
  end
106
111
 
107
112
  # A cache of the schema's merged possible types
@@ -338,7 +343,7 @@ module GraphQL
338
343
  end
339
344
 
340
345
  if allow_dynamic_queries == false && definition.name.nil?
341
- raise DynamicQueryError, "expected definition to be assigned to a static constant https://git.io/vXXSE"
346
+ raise DynamicQueryError, "expected definition to be assigned to a static constant https://github.com/github-community-projects/graphql-client/blob/master/guides/dynamic-query-error.md"
342
347
  end
343
348
 
344
349
  variables = deep_stringify_keys(variables)
@@ -403,7 +408,6 @@ module GraphQL
403
408
 
404
409
  doc.definitions.map do |node|
405
410
  deps = Set.new
406
- definitions = document_dependencies.definitions.map { |x| [x.name, x] }.to_h
407
411
 
408
412
  queue = [node.name]
409
413
  while name = queue.shift
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-24 00:00:00.000000000 Z
11
+ date: 2024-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 1.13.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 1.13.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: actionpack
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 1.57.0
131
+ version: 1.64.1
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 1.57.0
138
+ version: 1.64.1
139
139
  description: A Ruby library for declaring, composing and executing GraphQL queries
140
140
  email: engineering@github.com
141
141
  executables: []
@@ -180,11 +180,12 @@ files:
180
180
  - lib/graphql/client/view_module.rb
181
181
  - lib/rubocop/cop/graphql/heredoc.rb
182
182
  - lib/rubocop/cop/graphql/overfetch.rb
183
- homepage: https://github.com/github/graphql-client
183
+ homepage: https://github.com/github-community-projects/graphql-client
184
184
  licenses:
185
185
  - MIT
186
- metadata: {}
187
- post_install_message:
186
+ metadata:
187
+ rubygems_mfa_required: 'true'
188
+ post_install_message:
188
189
  rdoc_options: []
189
190
  require_paths:
190
191
  - lib
@@ -199,8 +200,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
200
  - !ruby/object:Gem::Version
200
201
  version: '0'
201
202
  requirements: []
202
- rubygems_version: 3.1.6
203
- signing_key:
203
+ rubygems_version: 3.5.9
204
+ signing_key:
204
205
  specification_version: 4
205
206
  summary: GraphQL Client
206
207
  test_files: []