Repository navigation
Standalone clients: --standalone writes a copy of the runtime into the output - #127
Merged
Merged
Conversation
Two clients that carry their own copy of the runtime share the app's IMemoryCache. With the same endpoint they produced the same key, and the second read the first's GraphQLSchema and failed with InvalidCastException.
scripts/spike-standalone.ps1 copies the runtime source and the generated SampleClient into projects with no Linq2GraphQL package reference, rewriting the namespace. The end-to-end tests run against the copy, and CoexistenceTests loads a 1.0.30 client and two current clients into one process.
In standalone mode the generated client depends on no Linq2GraphQL package: the runtime source (Client + Subscriptions, embedded in the generator at build time) is written to Runtime/ with its namespace rewritten to <namespace>.Runtime, and the generated client files point there too. Clients generated by different generator versions can then share an app, because each carries the runtime it was generated against. - Subscriptions runtime is only copied when subscriptions are generated. - Runtime/RuntimeInfo.cs records the runtime version and the packages it needs; the generator also prints them. - A Runtime folder from an earlier standalone run is cleared before writing. - Also settable as "standalone" in the config file. Replaces the spike. TestClientStandalone is now generated by regenerate-test-clients.ps1 (which ignores the version line in -Check), Linq2GraphQL.Tests.Standalone compiles the main suite's tests against it, and CoexistenceTests runs it next to the package-based client in one process.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Clients built and shipped as separate packages by different teams pin nothing about the runtime: an app that uses several of them gets one
Linq2GraphQL.Clientversion, whichever NuGet picks, which may not be the one each client was generated against. Today apps work around it by generating their own copies of the clients.What
--standalone(-sa, or"standalone": truein the settings file) makes the generator write a copy of the runtime intoRuntime/in the output, withLinq2GraphQL.Clientrewritten to<namespace>.Runtimein the runtime and the generated client. The client then references no Linq2GraphQL package, so clients of any generator version can share an app, next to package-mode clients.--subscriptions, AI with--agent) is embedded in the generator at build time, so it always matches the templates.Runtime/RuntimeInfo.csrecords the runtime version and the packages the copy needs; the generator prints them asPackageReferencelines.Runtimefolder from an earlier standalone run is cleared before writing.Fix found by the spike
The safe-mode schema cache key now includes the schema type. Two runtime copies sharing an app's
IMemoryCacheand an endpoint read each other's cached schema and failed withInvalidCastException.Tests
TestClientStandalone: checked-in standalone output, regenerated and checked byregenerate-test-clients.ps1(-Checkignores the version line inRuntimeInfo.cs).Linq2GraphQL.Tests.Standalonecompiles the main suite's test files against the standalone client, agent tests included: 436 pass.StandaloneGeneratorTestspins down what the generator emits;CoexistenceTestsruns a standalone and a package client in one process with a shared cache.Docs
Generator page, README and CHANGELOG describe the option and its trade-offs (runtime fixes arrive only by regenerating, each client has its own runtime types, the
Runtimefolder must not be edited).