Skip to content

Commit ae74a63

Browse files
Copilotxperiandri
andauthored
Refine hash span usage and test value explanation
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/020d0296-28b1-416d-bd12-9dd0790516ba Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
1 parent 85a30e9 commit ae74a63

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

src/FSharp.Data.GraphQL.Server/Executor.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type Executor<'Root>(schema: ISchema<'Root>, middlewares : IExecutorMiddleware s
8888
let canonicalQuery = document.ToQueryString()
8989
let queryBytes = Encoding.UTF8.GetBytes canonicalQuery
9090
let hash = SHA256.HashData queryBytes
91-
BinaryPrimitives.ReadInt32BigEndian(ReadOnlySpan<byte>(hash, 0, 4))
91+
BinaryPrimitives.ReadInt32BigEndian(hash.AsSpan(0, 4))
9292

9393
let rec runMiddlewares (phaseSel : IExecutorMiddleware -> ('ctx -> ('ctx -> 'res) -> 'res) option)
9494
(initialCtx : 'ctx)

tests/FSharp.Data.GraphQL.Tests/ExecutionTests.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ let ``Execution when querying returns unique document id with response`` () =
386386
let query = "query Example { a, b, a }"
387387
// Deterministic SHA-256-based documentId for canonical `query Example { a b a }`,
388388
// using the first 4 bytes of the hash as a big-endian int32.
389+
// Computed once via parse + ToQueryString + SHA-256 and kept fixed to catch regressions.
389390
let expectedDocumentId = -2063861555
390391
let result1 = sync <| Executor(schema).AsyncExecute(query, getMockInputContext, { A = "aa"; B = 2 })
391392
let result2 = sync <| Executor(schema).AsyncExecute(query, getMockInputContext, { A = "aa"; B = 2 })

0 commit comments

Comments
 (0)