Skip to content

Commit 334e080

Browse files
xperiandriclaude
andauthored
Build each Operation<...> instantiation of the client provider once (#620)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c390637 commit 334e080

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎RELEASE_NOTES.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,5 @@
324324
* Fixed `graphql-transport-ws` sending a request error (rejected before execution: validation, planning, variable coercion, a middleware, or the executor itself failing) as a `next` result followed by `complete`, instead of the terminal `error` message the protocol requires for it; a query or mutation whose non-null root field fails during execution still gets `next` + `complete`, since it is a result, not a request error
325325
* Fixed `graphql-transport-ws` throwing while serializing an `error` message or a `pong` carrying a payload, since neither was written under the `payload` property name `Utf8JsonWriter` requires
326326
* Fixed validation of an inline fragment without a type condition (`... { … }`), which used to fail with an exception instead of applying to the parent type
327+
* Fixed the GraphQL client provider building `Operation<...>` again for every file that uses the same operation, which added another operation type of the same name to `Operations` each time
327328
* Removed the internal `Observable.withCompletionMarker`

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,20 @@ module internal Provider =
937937
operationWrapper.AddMember(operationDef)
938938
operationDef.AddMember(methodDef)
939939
methodDef
940-
staticMethodDef.DefineStaticParameters(staticParams, instanceBuilder)
940+
// The compiler applies the same static arguments again for every file that uses an operation,
941+
// and each instantiation adds its operation type to Operations. A second type of the same name
942+
// makes the two incompatible (FS0193), so every instantiation is built once and then reused.
943+
// The lock also keeps the instantiations from adding members to Operations concurrently.
944+
let instances = Dictionary<string, ProvidedMethod>(StringComparer.Ordinal)
945+
let getOrBuildInstance (methodName : string) (args : obj []) =
946+
lock instances (fun () ->
947+
match instances.TryGetValue(methodName) with
948+
| true, instance -> instance
949+
| false, _ ->
950+
let instance = instanceBuilder methodName args
951+
instances.Add(methodName, instance)
952+
instance)
953+
staticMethodDef.DefineStaticParameters(staticParams, getOrBuildInstance)
941954
staticMethodDef
942955
let schemaPropertyDef =
943956
let getter = QuotationHelpers.quoteRecord schema (fun (_ : Expr list) schema -> schema)

0 commit comments

Comments
 (0)