graphql 1.12.5 → 1.12.6

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: 4ec7a782dba5df306d3e0590820d75d520b86651b9293417b115070057c45b8f
4
- data.tar.gz: 731f02ddfda3690ecd54cba1b1f373f9c8a53b65d422f853d44ddc9072fa85d7
3
+ metadata.gz: ebd2e71516a89475e1617ee60250d4d88f6d3743090ae8010e6918ce425a71fc
4
+ data.tar.gz: c0577dd5aac0765abf748f9ba86b3a3a814658abba7a2285b4e0d929959de50f
5
5
  SHA512:
6
- metadata.gz: e0783dea9b65037ea2d92b9ab88fc98153a541b0821f7b5d38bb53de3d33024a85d626302c8c92ddc9971606806c1a7896fb7a98da0c8c2261f9a034d87624e2
7
- data.tar.gz: c4b6035220bf578fc974a3fa437914dd5e652018b651b0c5af57f355e5d08b113a2faa2a6824242b71d01bab844767592f4d6ea5323e66e2ef05bcd74ad62df3
6
+ metadata.gz: 832d9464fe69bacc19d4a8715e5d2869d8ff15a4c1c34316d9c092b295e2175ac4f7a746a736773914ac4789478baa28a1f451c57cee732346901d5e4e10e430
7
+ data.tar.gz: 84f4918a0473bf07c657ca39392866ece0a36ca592272f85580417882b762e7210cd6404ee1671ad651ac7608acdb0103a4a262253e48ccc9b75be2804c5caf4
data/lib/graphql.rb CHANGED
@@ -4,7 +4,6 @@ require "json"
4
4
  require "set"
5
5
  require "singleton"
6
6
  require "forwardable"
7
- require_relative "./graphql/railtie" if defined? Rails::Railtie
8
7
 
9
8
  module GraphQL
10
9
  # forwards-compat for argument handling
@@ -103,6 +102,9 @@ require "graphql/scalar_type"
103
102
  require "graphql/name_validator"
104
103
 
105
104
  require "graphql/language"
105
+
106
+ require_relative "./graphql/railtie" if defined? Rails::Railtie
107
+
106
108
  require "graphql/analysis"
107
109
  require "graphql/tracing"
108
110
  require "graphql/dig"
@@ -6,6 +6,7 @@ require "graphql/language/document_from_schema_definition"
6
6
  require "graphql/language/generation"
7
7
  require "graphql/language/lexer"
8
8
  require "graphql/language/nodes"
9
+ require "graphql/language/cache"
9
10
  require "graphql/language/parser"
10
11
  require "graphql/language/token"
11
12
  require "graphql/language/visitor"
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'graphql/version'
4
+ require 'digest/sha2'
5
+
6
+ module GraphQL
7
+ module Language
8
+ class Cache
9
+ def initialize(path)
10
+ @path = path
11
+ end
12
+
13
+ DIGEST = Digest::SHA256.new << GraphQL::VERSION
14
+ def fetch(filename)
15
+ hash = DIGEST.dup << filename
16
+ begin
17
+ hash << File.mtime(filename).to_i.to_s
18
+ rescue SystemCallError
19
+ return yield
20
+ end
21
+ cache_path = @path.join(hash.to_s)
22
+
23
+ if cache_path.exist?
24
+ Marshal.load(cache_path.read)
25
+ else
26
+ payload = yield
27
+ tmp_path = "#{cache_path}.#{rand}"
28
+
29
+ @path.mkpath
30
+ File.binwrite(tmp_path, Marshal.dump(payload))
31
+ File.rename(tmp_path, cache_path.to_s)
32
+ payload
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -41,12 +41,22 @@ def parse_document
41
41
  end
42
42
  end
43
43
 
44
- def self.parse(query_string, filename: nil, tracer: GraphQL::Tracing::NullTracer)
45
- self.new(query_string, filename: filename, tracer: tracer).parse_document
46
- end
44
+ class << self
45
+ attr_accessor :cache
46
+
47
+ def parse(query_string, filename: nil, tracer: GraphQL::Tracing::NullTracer)
48
+ new(query_string, filename: filename, tracer: tracer).parse_document
49
+ end
47
50
 
48
- def self.parse_file(filename, tracer: GraphQL::Tracing::NullTracer)
49
- self.parse(File.read(filename), filename: filename, tracer: tracer)
51
+ def parse_file(filename, tracer: GraphQL::Tracing::NullTracer)
52
+ if cache
53
+ cache.fetch(filename) do
54
+ parse(File.read(filename), filename: filename, tracer: tracer)
55
+ end
56
+ else
57
+ parse(File.read(filename), filename: filename, tracer: tracer)
58
+ end
59
+ end
50
60
  end
51
61
 
52
62
  private
@@ -462,12 +462,22 @@ def parse_document
462
462
  end
463
463
  end
464
464
 
465
- def self.parse(query_string, filename: nil, tracer: GraphQL::Tracing::NullTracer)
466
- self.new(query_string, filename: filename, tracer: tracer).parse_document
467
- end
465
+ class << self
466
+ attr_accessor :cache
467
+
468
+ def parse(query_string, filename: nil, tracer: GraphQL::Tracing::NullTracer)
469
+ new(query_string, filename: filename, tracer: tracer).parse_document
470
+ end
468
471
 
469
- def self.parse_file(filename, tracer: GraphQL::Tracing::NullTracer)
470
- self.parse(File.read(filename), filename: filename, tracer: tracer)
472
+ def parse_file(filename, tracer: GraphQL::Tracing::NullTracer)
473
+ if cache
474
+ cache.fetch(filename) do
475
+ parse(File.read(filename), filename: filename, tracer: tracer)
476
+ end
477
+ else
478
+ parse(File.read(filename), filename: filename, tracer: tracer)
479
+ end
480
+ end
471
481
  end
472
482
 
473
483
  private
@@ -45,6 +45,9 @@ module GraphQL
45
45
  end
46
46
  end
47
47
 
48
+ # @return [Hash<Symbol => Object>] The field arguments from the field that returned this connection
49
+ attr_accessor :arguments
50
+
48
51
  # @param items [Object] some unpaginated collection item, like an `Array` or `ActiveRecord::Relation`
49
52
  # @param context [Query::Context]
50
53
  # @param parent [Object] The object this collection belongs to
@@ -52,8 +55,9 @@ module GraphQL
52
55
  # @param after [String, nil] A cursor for pagination, if the client provided one
53
56
  # @param last [Integer, nil] Limit parameter from the client, if provided
54
57
  # @param before [String, nil] A cursor for pagination, if the client provided one.
58
+ # @param arguments [Hash] The arguments to the field that returned the collection wrapped by this connection
55
59
  # @param max_page_size [Integer, nil] A configured value to cap the result size. Applied as `first` if neither first or last are given.
56
- def initialize(items, parent: nil, field: nil, context: nil, first: nil, after: nil, max_page_size: :not_given, last: nil, before: nil, edge_class: nil)
60
+ def initialize(items, parent: nil, field: nil, context: nil, first: nil, after: nil, max_page_size: :not_given, last: nil, before: nil, edge_class: nil, arguments: nil)
57
61
  @items = items
58
62
  @parent = parent
59
63
  @context = context
@@ -62,6 +66,7 @@ module GraphQL
62
66
  @after_value = after
63
67
  @last_value = last
64
68
  @before_value = before
69
+ @arguments = arguments
65
70
  @edge_class = edge_class || self.class::Edge
66
71
  # This is only true if the object was _initialized_ with an override
67
72
  # or if one is assigned later.
@@ -84,6 +84,7 @@ module GraphQL
84
84
  after: arguments[:after],
85
85
  last: arguments[:last],
86
86
  before: arguments[:before],
87
+ arguments: arguments,
87
88
  edge_class: edge_class_for_field(field),
88
89
  )
89
90
  end
@@ -32,7 +32,11 @@ module GraphQL
32
32
  @has_next_page = if before_offset && before_offset > 0
33
33
  true
34
34
  elsif first
35
- relation_count(set_limit(sliced_nodes, first + 1)) == first + 1
35
+ if @nodes && @nodes.count < first
36
+ false
37
+ else
38
+ relation_count(set_limit(sliced_nodes, first + 1)) == first + 1
39
+ end
36
40
  else
37
41
  false
38
42
  end
@@ -1,8 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
-
4
3
  module GraphQL
5
4
  class Railtie < Rails::Railtie
5
+ config.before_configuration do
6
+ # Bootsnap compile cache has similar expiration properties,
7
+ # so we assume that if the user has bootsnap setup it's ok
8
+ # to piggy back on it.
9
+ if ::Object.const_defined?("Bootsnap::CompileCache::ISeq") && Bootsnap::CompileCache::ISeq.cache_dir
10
+ Language::Parser.cache ||= Language::Cache.new(Pathname.new(Bootsnap::CompileCache::ISeq.cache_dir).join('graphql'))
11
+ end
12
+ end
13
+
6
14
  rake_tasks do
7
15
  # Defer this so that you only need the `parser` gem when you _run_ the upgrader
8
16
  def load_upgraders
@@ -42,6 +42,7 @@ module GraphQL
42
42
  value.after_value ||= original_arguments[:after]
43
43
  value.last_value ||= original_arguments[:last]
44
44
  value.before_value ||= original_arguments[:before]
45
+ value.arguments ||= original_arguments
45
46
  value.field ||= field
46
47
  if field.has_max_page_size? && !value.has_max_page_size_override?
47
48
  value.max_page_size = field.max_page_size
@@ -29,8 +29,8 @@ module GraphQL
29
29
  context.directive_definition.arguments
30
30
  when GraphQL::Language::Nodes::InputObject
31
31
  arg_type = context.argument_definition.type.unwrap
32
- if arg_type.is_a?(GraphQL::InputObjectType)
33
- arguments = arg_type.input_fields
32
+ if arg_type.kind.input_object?
33
+ arguments = arg_type.arguments
34
34
  else
35
35
  # This is some kind of error
36
36
  nil
@@ -3,8 +3,9 @@
3
3
  module GraphQL
4
4
  module Tracing
5
5
  # This implementation forwards events to ActiveSupport::Notifications
6
- # with a `graphql.` prefix.
6
+ # with a `graphql` suffix.
7
7
  #
8
+ # @see KEYS for event names
8
9
  module ActiveSupportNotificationsTracing
9
10
  # A cache of frequently-used keys to avoid needless string allocations
10
11
  KEYS = {
@@ -12,6 +12,8 @@ module GraphQL
12
12
  child_class.extend(Relay::DefaultRelay)
13
13
  child_class.default_relay(true)
14
14
  child_class.node_nullable(true)
15
+ child_class.edges_nullable(true)
16
+ child_class.edge_nullable(true)
15
17
  add_page_info_field(child_class)
16
18
  end
17
19
 
@@ -32,7 +34,7 @@ module GraphQL
32
34
  # It's called when you subclass this base connection, trying to use the
33
35
  # class name to set defaults. You can call it again in the class definition
34
36
  # to override the default (or provide a value, if the default lookup failed).
35
- def edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type, nodes_field: true, node_nullable: self.node_nullable)
37
+ def edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type, nodes_field: true, node_nullable: self.node_nullable, edges_nullable: self.edges_nullable, edge_nullable: self.edge_nullable)
36
38
  # Set this connection's graphql name
37
39
  node_type_name = node_type.graphql_name
38
40
 
@@ -40,8 +42,8 @@ module GraphQL
40
42
  @edge_type = edge_type_class
41
43
  @edge_class = edge_class
42
44
 
43
- field :edges, [edge_type_class, null: true],
44
- null: true,
45
+ field :edges, [edge_type_class, null: edge_nullable],
46
+ null: edges_nullable,
45
47
  description: "A list of edges.",
46
48
  legacy_edge_class: edge_class, # This is used by the old runtime only, for EdgesInstrumentation
47
49
  connection: false
@@ -83,6 +85,26 @@ module GraphQL
83
85
  end
84
86
  end
85
87
 
88
+ # Set the default `edges_nullable` for this class and its child classes. (Defaults to `true`.)
89
+ # Use `edges_nullable(false)` in your base class to make non-null `edges` fields.
90
+ def edges_nullable(new_value = nil)
91
+ if new_value.nil?
92
+ @edges_nullable || superclass.edges_nullable
93
+ else
94
+ @edges_nullable ||= new_value
95
+ end
96
+ end
97
+
98
+ # Set the default `edge_nullable` for this class and its child classes. (Defaults to `true`.)
99
+ # Use `edge_nullable(false)` in your base class to make non-null `edge` fields.
100
+ def edge_nullable(new_value = nil)
101
+ if new_value.nil?
102
+ @edge_nullable || superclass.edge_nullable
103
+ else
104
+ @edge_nullable ||= new_value
105
+ end
106
+ end
107
+
86
108
  private
87
109
 
88
110
  def define_nodes_field(nullable)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "1.12.5"
3
+ VERSION = "1.12.6"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.5
4
+ version: 1.12.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-18 00:00:00.000000000 Z
11
+ date: 2021-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips
@@ -414,6 +414,7 @@ files:
414
414
  - lib/graphql/invalid_null_error.rb
415
415
  - lib/graphql/language.rb
416
416
  - lib/graphql/language/block_string.rb
417
+ - lib/graphql/language/cache.rb
417
418
  - lib/graphql/language/definition_slice.rb
418
419
  - lib/graphql/language/document_from_schema_definition.rb
419
420
  - lib/graphql/language/generation.rb