Skip to content

Commit

Permalink
cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmac committed Sep 15, 2024
1 parent f7cccba commit abd2fbd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
18 changes: 12 additions & 6 deletions lib/graphql/stitching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,24 @@ class CompositionError < StitchingError; end
class ValidationError < CompositionError; end

class << self
def digest_class
@digest_class ||= Digest::SHA2
end
attr_writer :stitch_directive

attr_writer :digest_class
# Proc used to compute digests; uses SHA2 by default.
# @returns [Proc] proc used to compute digests.
def digest(&block)
if block_given?
@digest = block
else
@digest ||= ->(str) { Digest::SHA2.hexdigest(str) }
end
end

# Name of the directive used to mark type resolvers.
# @returns [String] name of the type resolver directive.
def stitch_directive
@stitch_directive ||= "stitch"
end

attr_writer :stitch_directive

# Names of stitching directives to omit from the composed supergraph.
# @returns [Array<String>] list of stitching directive names.
def stitching_directive_names
Expand Down
4 changes: 2 additions & 2 deletions lib/graphql/stitching/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ def normalized_string

# @return [String] a digest of the original document string. Generally faster but less consistent.
def digest
@digest ||= Stitching.digest_class.hexdigest("#{Stitching::VERSION}/#{string}")
@digest ||= Stitching.digest.call("#{Stitching::VERSION}/#{string}")
end

# @return [String] a digest of the normalized document string. Slower but more consistent.
def normalized_digest
@normalized_digest ||= Stitching.digest_class.hexdigest("#{Stitching::VERSION}/#{normalized_string}")
@normalized_digest ||= Stitching.digest.call("#{Stitching::VERSION}/#{normalized_string}")
end

# @return [GraphQL::Language::Nodes::OperationDefinition] The selected root operation for the request.
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/stitching/type_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def list?
end

def version
@version ||= Stitching.digest_class.hexdigest("#{Stitching::VERSION}/#{as_json.to_json}")
@version ||= Stitching.digest.call("#{Stitching::VERSION}/#{as_json.to_json}")
end

def ==(other)
Expand Down

0 comments on commit abd2fbd

Please sign in to comment.