Skip to content

Commit 85a30e9

Browse files
Copilotxperiandri
andauthored
Clarify hash truncation and expected documentId derivation
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 cbd142f commit 85a30e9

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ type Executor<'Root>(schema: ISchema<'Root>, middlewares : IExecutorMiddleware s
8383
let middlewaresList = Seq.toList middlewares
8484

8585
/// Generates a deterministic document identifier from the canonical query string.
86+
/// The SHA-256 hash is truncated to 32 bits to preserve the existing int32 documentId contract.
8687
let getDocumentId (document : Document) =
8788
let canonicalQuery = document.ToQueryString()
8889
let queryBytes = Encoding.UTF8.GetBytes canonicalQuery

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ let ``Execution when querying returns unique document id with response`` () =
384384
Define.Field("b", IntType, fun _ x -> x.B)
385385
]))
386386
let query = "query Example { a, b, a }"
387-
// Deterministic SHA-256-based documentId for the canonical AST query string above.
387+
// Deterministic SHA-256-based documentId for canonical `query Example { a b a }`,
388+
// using the first 4 bytes of the hash as a big-endian int32.
388389
let expectedDocumentId = -2063861555
389390
let result1 = sync <| Executor(schema).AsyncExecute(query, getMockInputContext, { A = "aa"; B = 2 })
390391
let result2 = sync <| Executor(schema).AsyncExecute(query, getMockInputContext, { A = "aa"; B = 2 })

0 commit comments

Comments
 (0)