Skip to content

Commit

Permalink
Handle nil query_string in fingerprint
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed May 20, 2024
1 parent a8e381c commit e418d4d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Gemfile.lock
gemfiles/*.lock
# Test database
*.db
*.db-shm
*.db-wal
.byebug_history
.bundle/
vendor/
.idea/
Expand All @@ -17,7 +20,6 @@ _site
.jekyll-cache
gh-pages/
tmp/*
__*.db
node_modules/
yarn.lock
OperationStoreClient.js
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def fingerprint

# @return [String] An opaque hash for identifying this query's given query string and selected operation
def operation_fingerprint
@operation_fingerprint ||= "#{selected_operation_name || "anonymous"}/#{Fingerprint.generate(query_string)}"
@operation_fingerprint ||= "#{selected_operation_name || "anonymous"}/#{Fingerprint.generate(query_string || "")}"
end

# @return [String] An opaque hash for identifying this query's given a variable values (not including defaults)
Expand Down
8 changes: 8 additions & 0 deletions spec/graphql/query/fingerprint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def build_query(str, var)
assert_equal op_name_expected_fingerprint, build_query(str3, {}).operation_fingerprint
end

it "returns a fingerprint when the query string is blank or nil" do
nil_query = build_query(nil, {})
blank_query = build_query("", {})

assert_equal "anonymous/47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU=", blank_query.operation_fingerprint
assert_equal "anonymous/47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU=", nil_query.operation_fingerprint
end

it "makes combined fingerprints" do
str1a = "{ __typename }"
str1b = "{ __typename }"
Expand Down

0 comments on commit e418d4d

Please sign in to comment.