Skip to content

Commit 7a0a627

Browse files
Copilotxperiandri
andauthored
Apply follow-up review suggestions
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/f1a0e6cb-a5dd-40d9-a7dc-28e030b8e56f Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
1 parent b45c4ea commit 7a0a627

5 files changed

Lines changed: 6 additions & 13 deletions

File tree

docs/execution-pipeline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The execution phase can be performed using one of the two strategies:
5252

5353
The result of a GraphQL query execution is a `GQLResponse` object with the following fields:
5454

55-
- `documentId`: deterministic SHA-256 hash (lowercase hex string) of the canonical query document - it can be used to implement execution plan caching (persistent queries).
55+
- `documentId`: deterministic SHA-256 hash (lowercase hex string) of the canonical query document it can be used to implement execution plan caching (persistent queries).
5656
- `data`: optional, a formatted GraphQL response matching the requested query (`KeyValuePair seq`). Absent in case of an error that does not allow continuing processing and returning any GraphQL results.
5757
- `errors`: optional, contains a list of errors (`GQLProblemDetails`) that occurred during query execution.
5858

src/FSharp.Data.GraphQL.Client.DesignTime/ProvidedTypesHelper.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ module internal Provider =
799799
match validationResult with
800800
| ValidationError msgs -> failwith (formatValidationExceptionMessage msgs)
801801
| Success -> ()
802-
let key = { DocumentId = DocumentId.fromDocument queryAst; SchemaId = schema.GetHashCode() }
802+
let key = { DocumentId = DocumentId.fromCanonicalQuery (queryAst.ToQueryString()); SchemaId = schema.GetHashCode() }
803803
let refMaker = lazy Validation.Ast.validateDocument schema queryAst
804804
if clientQueryValidation then
805805
refMaker.Force

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ type Executor<'Root>(schema: ISchema<'Root>, middlewares : IExecutorMiddleware s
7979

8080
let middlewaresList = Seq.toList middlewares
8181

82-
/// Generates a deterministic document identifier from the canonical query string.
83-
let getDocumentId (document : Document) =
84-
DocumentId.fromDocument document
85-
8682
let rec runMiddlewares (phaseSel : IExecutorMiddleware -> ('ctx -> ('ctx -> 'res) -> 'res) option)
8783
(initialCtx : 'ctx)
8884
(onComplete : 'ctx -> 'res)
@@ -143,7 +139,7 @@ type Executor<'Root>(schema: ISchema<'Root>, middlewares : IExecutorMiddleware s
143139
eval (executionPlan, data, variables, getInputContext)
144140

145141
let createExecutionPlan (ast: Document, operationName: string option, meta : Metadata) =
146-
let documentId = getDocumentId ast
142+
let documentId = DocumentId.fromCanonicalQuery (ast.ToQueryString())
147143
result {
148144
match findOperation ast operationName with
149145
| Some operation ->

src/FSharp.Data.GraphQL.Shared/FSharp.Data.GraphQL.Shared.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@
4949
<Compile Include="Helpers\Extensions.fs" />
5050
<Compile Include="Helpers\Reflection.fs" />
5151
<Compile Include="Helpers\MemoryCache.fs" />
52+
<Compile Include="Helpers\DocumentId.fs" />
5253
<Compile Include="Errors.fs" />
5354
<Compile Include="Exception.fs" />
5455
<Compile Include="ValidationTypes.fs" />
5556
<Compile Include="AsyncVal.fs" />
5657
<Compile Include="Ast.fs" />
5758
<Compile Include="AstExtensions.fs" />
58-
<Compile Include="Helpers\DocumentId.fs" />
5959
<Compile Include="TypeSystem.fs" />
6060
<Compile Include="SchemaDefinitions.fs" />
6161
<Compile Include="SchemaDefinitionsExtensions.fs" />

src/FSharp.Data.GraphQL.Shared/Helpers/DocumentId.fs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ module FSharp.Data.GraphQL.DocumentId
33
open System.Globalization
44
open System.Security.Cryptography
55
open System.Text
6-
open FSharp.Data.GraphQL.Ast
7-
open FSharp.Data.GraphQL.Ast.Extensions
86

97
let private formatByteAsLowerHex (value : byte) =
108
value.ToString("x2", CultureInfo.InvariantCulture)
119

12-
let fromDocument (document : Document) =
13-
let canonicalQuery = document.ToQueryString()
10+
let fromCanonicalQuery (canonicalQuery : string) =
1411
let queryBytes = Encoding.UTF8.GetBytes canonicalQuery
1512
use sha256 = SHA256.Create()
1613
let hash = sha256.ComputeHash queryBytes
1714
hash
18-
|> Array.map formatByteAsLowerHex
15+
|> Seq.map formatByteAsLowerHex
1916
|> String.concat ""

0 commit comments

Comments
 (0)