@@ -3,12 +3,6 @@ namespace FSharp.Data.GraphQL.Validation
33open FSharp.Data .GraphQL
44open FSharp.Data .GraphQL .Types .Introspection
55open System
6- open System.IO
7- open System.Security .Cryptography
8- open System.Text
9- open System.Text .Encodings .Web
10- open System.Text .Json
11- open System.Text .Json .Serialization
126
137type ValidationResultKey =
148 { DocumentId : string
@@ -21,35 +15,14 @@ type IValidationResultCache =
2115 abstract GetOrAdd : ValidationResultProducer -> ValidationResultKey -> ValidationResult < GQLProblemDetails >
2216
2317module SchemaId =
24-
25- let private formatByteAsLowerHex ( value : byte ) =
26- value.ToString( " x2" , System.Globalization.CultureInfo.InvariantCulture)
27-
28- // Note: UnsafeRelaxedJsonEscaping is used here only for deterministic hashing,
29- // not for output to untrusted contexts. The JSON is never exposed externally.
30- let private jsonOptions = JsonSerializerOptions(
31- WriteIndented = false ,
32- DefaultIgnoreCondition = JsonIgnoreCondition.Never,
33- PropertyNamingPolicy = null ,
34- Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
35- )
36-
3718 /// <summary >
38- /// Computes a deterministic schema identifier from an introspection schema.
19+ /// Computes an in-memory schema identifier from an introspection schema instance .
3920 /// </summary >
40- /// <param name =" introspectionSchema " >The introspection schema to hash .</param >
41- /// <returns >A lowercase hexadecimal SHA-256 hash string that uniquely identifies the schema structure .</returns >
21+ /// <param name =" introspectionSchema " >The introspection schema.</param >
22+ /// <returns >A string representation of the schema hash code .</returns >
4223 [<CompiledName( " FromIntrospectionSchema" ) >]
4324 let fromIntrospectionSchema ( introspectionSchema : IntrospectionSchema ) =
44- use stream = new MemoryStream()
45- JsonSerializer.Serialize( stream, introspectionSchema, jsonOptions)
46- // Note: Creating SHA256 instance per call is acceptable since schema ID computation
47- // happens infrequently (typically once per schema during validation cache key creation)
48- use sha256 = SHA256.Create()
49- let hash = sha256.ComputeHash( stream.ToArray())
50- hash
51- |> Seq.map formatByteAsLowerHex
52- |> String.concat " "
25+ introspectionSchema.GetHashCode() .ToString( System.Globalization.CultureInfo.InvariantCulture)
5326
5427/// An in-memory cache for the results of schema/document validations, with a lifetime of 30 seconds.
5528type MemoryValidationResultCache () =
0 commit comments