graphql-client 0.20.0 → 0.22.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: d645f13f9acd753d166f82ceea2e8a19fe8695ff2e00ac7ae505a2b0f784560e
4
- data.tar.gz: ffa8a0bf2a8264314395494cac66960d7ade04e5eae650d57e19c76c9f64d5f8
3
+ metadata.gz: 4064d832c0bf6433b6b6629c50d5c20182164bb6e870661d670fd6ba3ab0ecdc
4
+ data.tar.gz: 21f4aea0033c36f86d14ae4fe52294ae0193cc1485154cf3b15519b9ac0b8d8f
5
5
  SHA512:
6
- metadata.gz: 73836d82fe18274ac579b2426c1625a76248cba2ae04dd51bdea84baecaeb550197958a8359ffcce5bcec8016f2d874751ac5fbe28ca509ddc0c49eaa22d356e
7
- data.tar.gz: c3f3e78d79d2147ec051569ff807c75740ed3b92407ca18c3c1d4b11b7af557782b26acdf0207892e10ae8e65c572bb08d1ba1b611c883291f71befca55d47be
6
+ metadata.gz: 4507464c1a14fcac7aecaacf07d9b8297f288b717d7c59e12368426b427d5bdeacf7c19fd3e037df8d26482ad719b8edfc2dd26665d8d59518a10720ab1968c0
7
+ data.tar.gz: f1c34616ea07b5bb4926f7489225859b3b9bff50485a90d74a55f9ce4e4aca74eeb5420cb793522470de9ac3ccbf85628ac0d3c3b0e01955024aebaf5a420d37
@@ -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
@@ -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: [])
@@ -101,7 +101,7 @@ module GraphQL
101
101
  if schema.is_a?(Class)
102
102
  @possible_types = schema.possible_types
103
103
  end
104
- @types = Schema.generate(@schema)
104
+ @types = Schema.generate(@schema, raise_on_unknown_enum_value: raise_on_unknown_enum_value)
105
105
  end
106
106
 
107
107
  # A cache of the schema's merged possible types
@@ -338,7 +338,7 @@ module GraphQL
338
338
  end
339
339
 
340
340
  if allow_dynamic_queries == false && definition.name.nil?
341
- raise DynamicQueryError, "expected definition to be assigned to a static constant https://git.io/vXXSE"
341
+ 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
342
  end
343
343
 
344
344
  variables = deep_stringify_keys(variables)
@@ -403,7 +403,6 @@ module GraphQL
403
403
 
404
404
  doc.definitions.map do |node|
405
405
  deps = Set.new
406
- definitions = document_dependencies.definitions.map { |x| [x.name, x] }.to_h
407
406
 
408
407
  queue = [node.name]
409
408
  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.20.0
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-08 00:00:00.000000000 Z
11
+ date: 2024-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport