Repository navigation
feat(gremlin): describe how a record is stored in a graph - #76
xperiandri wants to merge 2 commits into
Conversation
The Gremlin libraries are two packages from the start. `FSharp.Gremlin` is the core and does not depend on a provider. `FSharp.Azure.Cosmos.Gremlin` adds Azure Cosmos DB for Apache Gremlin. A client of a TinkerPop Gremlin Server references the core alone. `src/Gremlin` contains the types that a graph model declares: `LabelAttribute`, which sets the label of a record type, `PartitionKeyAttribute`, which marks the field that holds the partition key, and the struct record `VertexProperty<'Value, 'Meta>`, a vertex property with its meta-properties. `src/Cosmos.Gremlin` contains `CosmosGremlinConnection`, the settings of a graph: `azure` for an account in Azure (port 443 with TLS) and `emulator` for the local emulator (port 8901 without TLS, the well-known key). On 2026-11-08 the emulator accepted only `ws` on port 8901, and the TLS handshake of `wss` failed. `ToString`, `%A` and an interpolated string of the settings show `Description`, which does not contain the key. `azure` refuses an account name that does not obey the rule of Azure. The two functions refuse an id that Cosmos DB does not allow, and an id that ends in a space, which Data Explorer refuses. No package is made of the two projects until a query runs end to end. Each project has a test project: `tests/Gremlin.Tests` and `tests/Cosmos.Gremlin.Tests`. The test layout instruction lists their groups of test categories, so the two test files of the graph model are in `tests/Gremlin.Tests/GraphModel/`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved naming and validation defects can desynchronize serialization from graph models, admit invalid or ambiguous property keys, omit serialized members, and incorrectly reject Id-based partition keys.
6 open issues
Model or reject additional serialized record properties · New Reject duplicate value and meta wrapper names · New Reject empty and hidden effective property names · New Include Id in name-based partition-key lookup · New Validate the effective record converter and its settings · New Honor effective member overrides when resolving field names · New
What changed in this PR
Adds the record-to-graph model that future Gremlin encoding, materialization, and query components will use. This PR also includes the core/provider project scaffolding from #75.
Changes:
- Models labels, ids, partition keys, property shapes, and meta-properties, with cached models and field-specific validation errors.
- Reads serializer settings and naming rules, with unit tests and serializer compatibility checks.
- Adds Azure Cosmos DB Gremlin connection settings and integrates both libraries and test projects into the solution.
| File | Description |
|---|---|
| tests/Gremlin.Tests/testconfig.json | Enables parallel unit tests. |
| tests/Gremlin.Tests/TestCategories.fs | Defines graph-model and serializer test categories. |
| tests/Gremlin.Tests/Profiles.fs | Supplies serializer configurations for tests. |
| tests/Gremlin.Tests/GraphRecords.fs | Defines accepted and rejected record fixtures. |
| tests/Gremlin.Tests/GraphModel/VertexPropertyTests.fs | Tests vertex-property helpers and equality. |
| tests/Gremlin.Tests/GraphModel/SerializerProfileTests.fs | Tests supported settings and serializer assumptions. |
| tests/Gremlin.Tests/GraphModel/GraphModelTests.fs | Tests model construction, caching, and validation. |
| tests/Gremlin.Tests/GraphModel/AttributeTests.fs | Checks graph attributes through reflection. |
| tests/Gremlin.Tests/FSharp.Gremlin.Tests.fsproj | Configures the core unit-test project. |
| tests/Cosmos.Gremlin.Tests/testconfig.json | Enables parallel connection tests. |
| tests/Cosmos.Gremlin.Tests/TestCategories.fs | Defines the connection test category. |
| tests/Cosmos.Gremlin.Tests/FSharp.Azure.Cosmos.Gremlin.Tests.fsproj | Configures the provider test project. |
| tests/Cosmos.Gremlin.Tests/CosmosGremlinConnectionTests.fs | Tests connection defaults, validation, and formatting. |
| src/Gremlin/VertexProperty.fs | Adds values with typed meta-properties. |
| src/Gremlin/SerializerProfile.fs | Validates serializer settings and resolves names and shapes. |
| src/Gremlin/GraphModelException.fs | Adds record- and field-specific model errors. |
| src/Gremlin/GraphModel.fs | Builds, validates, and caches graph models. |
| src/Gremlin/FSharp.Gremlin.fsproj | Defines the provider-independent core project. |
| src/Gremlin/ElementModel.fs | Defines public graph-model types and options. |
| src/Gremlin/Attributes.fs | Adds label and partition-key attributes. |
| src/Gremlin/AssemblyInfo.fs | Adds core assembly metadata. |
| src/Cosmos.Gremlin/FSharp.Azure.Cosmos.Gremlin.fsproj | Defines the Cosmos DB provider project. |
| src/Cosmos.Gremlin/CosmosGremlinConnection.fs | Adds Azure and emulator connection settings. |
| src/Cosmos.Gremlin/AssemblyInfo.fs | Adds provider assembly metadata. |
| FSharp.Azure.Cosmos.slnx | Includes the new libraries and tests. |
| FSharp.Azure.Cosmos.slnf | Includes the new projects in the solution filter. |
| Directory.Packages.props | Centrally pins FSharp.SystemTextJson. |
| .github/instructions/test-layout.instructions.md | Documents the Gremlin test groups. |
| .github/copilot-instructions.md | Documents the new project structure. |
Review effort: Balanced
The next steps of the Gremlin libraries (the encoder of values, the Groovy writer, the materializer and the predicates) have to know how a graph stores a record. `GraphModel.create` reads the options of the serializer one time. Then `VertexOf`, `EdgeOf` and `MetaOf` give for each record type its label, its id, its partition key and its properties. For each property, the model gives the name, whether the property can be absent, and the shape: one value, a list of values, one value with meta-properties, or a list of values with meta-properties. The names are the names that FSharp.SystemTextJson writes: `JsonName` first, then `JsonPropertyName`, then the naming policy. These are the rules of the narrow layout of the Quotations library, and the model accepts the same options: one converter of FSharp.SystemTextJson that writes every kind of type and writes an option as its value, no handling of references, no numbers as texts, and no ignored read-only members. The model also refuses the properties of records (IncludeRecordProperties) and the attributes that the options replace by the name of a member (WithOverrideMembers). The serializer must take that converter for the record, and not a record converter that comes before it among the options. The model refuses what a graph cannot store, with a message that names the record, the field and the reason. Examples are a class, a record that another converter writes or that has options of its own, a field that is not written as a string, a number or a Boolean, a public property with `JsonInclude`, an empty name, a name that starts with ~, an option of an option, `Nullable`, an optional list, a list of lists, a vertex without an id, a list or meta-properties on an edge, and a partition key that is absent, optional or given two times. FSharp.SystemTextJson 1.4.36 throws `NullReferenceException` when it reads a record with an ignored field of a value type (issue 217 of FSharp.SystemTextJson), so the model refuses such a field too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
63c63fd to
066d432
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved serializer read-name collisions can lose data or fail deserialization, while accepted hidden labels and partition keys cannot be written by Gremlin.
4 open issues
6 resolved since last review
Honor effective member overrides when resolving field names Validate the effective record converter and its settings Include Id in name-based partition-key lookup Reject empty and hidden effective property names Reject duplicate value and meta wrapper names Model or reject additional serialized record properties
Review effort: Balanced
| if not (names.Add property.Name) then | ||
| refuseField recordType role property.Member $"another field has the name {property.Name} too." |
|
|
||
| // FSharp.SystemTextJson writes the value and the meta-properties of a vertex property under these names, so a | ||
| // reader can tell them apart only when the names differ | ||
| if String.Equals (valueName, metaName, StringComparison.Ordinal) then |
| let private labelOf (recordType : Type) (role : Role) : string = | ||
| match recordType.GetCustomAttribute<LabelAttribute> false with | ||
| | null -> | ||
| if recordType.IsGenericType then | ||
| refuseRecord | ||
| recordType | ||
| role | ||
| "a generic type needs LabelAttribute, because the name of the type ends with the number of its type parameters." | ||
|
|
||
| recordType.Name | ||
| | attribute when String.IsNullOrWhiteSpace attribute.Label -> | ||
| refuseRecord recordType role "its LabelAttribute gives an empty label." | ||
| | attribute -> attribute.Label |
| -> | ||
| ImmutableArray.Create | ||
| $"Azure Cosmos DB does not accept /{name} as the partition key of a graph, and Gremlin keeps the property name {name}." | ||
| | ValueSome _ -> ImmutableArray.Empty |


Summary
Step 3 of the plan for the Gremlin libraries. The next steps (the encoder of values, the Groovy writer, the materializer, the predicates) have to know how a graph stores an F# record.
GraphModelgives the label, the id, the partition key, and for each property its name and its shape. It refuses at once what a graph cannot store, with a message that names the record, the field and the reason.This pull request contains the commit of #75 (
757ac46), which adds the projects. CI runs only for pull requests intomain, so the base ismain. After #75 merges, I rebase this branch.What the model gives
GraphModel.create options serializerOptionsreads the options of the serializer one time, and gives the model or the reasons why it cannot work with them.VertexOf,EdgeOfandMetaOfgive the model of a record type, made one time and kept. Many threads can ask at the same time.ElementModel: the label (the label of[<Label>]or the name of the type, as ExRam.Gremlinq writes it), the fieldId, the partition key, and the other fields as properties.PropertyModel: the name, whether the field can be absent (Required,ValueOption,Option), and the shape:Scalar,ScalarList,WithMeta(aVertexProperty) orWithMetaList.PartitionKeyModel: withGraphModelOptions.PartitionKeyProperty(Azure Cosmos DB), the field with[<PartitionKey>]or the field with that name (alsoId) gives the partition key, for SkillGroCompanyIdfor the propertyPartitionKey. Without the setting (TinkerPop), the attribute has no effect, so one record works with the two providers.The name of a property is the name that FSharp.SystemTextJson writes:
[<JsonName>], then[<JsonPropertyName>], then the naming policy. These are the rules of the narrow layout (#65), and the model accepts the same options. A graph that ExRam.Gremlinq wrote keeps its names when the graph gets options without a naming policy.What the model refuses
UnwrapOption,IncludeRecordProperties,WithOverrideMembers, references, numbers as texts, ignored read-only members; a partition key property that is empty, has a slash, or isidorlabel.JsonInclude, a generic record without[<Label>], an empty label, a naming policy that givesValueandMetaofVertexPropertyone name.Nullable(declare avoption), an optional list, a list of options or of lists, the namesidandlabel, an empty name, a name that starts with~(TinkerPop keeps it for hidden keys), two fields with one name, a vertex property of a list or an option.Id, an optional or list id of a vertex, no partition key, two of them, or one that is optional or ignored.[<JsonIgnore>]: FSharp.SystemTextJson 1.4.36 throwsNullReferenceExceptionwhen it reads such a record (Tarmil/FSharp.SystemTextJson#217).Tests
tests/Gremlin.Tests/GraphModel: 104 tests, 98 of them new.GraphModelTests: records in the shape of SkillGro, and one row for each refusal.SerializerProfileTests: the five set-ups that the model accepts (FSharp.SystemTextJson defaults, camel case, snake case, SkillGro, Ecierge), each refusal of the options, and canaries: tests of the facts of FSharp.SystemTextJson that the model depends on, so a new version that changes a fact fails a test.Not in this change
The encoder of step 4 checks each value: a union with fields passes the model and is refused when a value is encoded. The model refuses the records of
AllowNullFSharpRecordConverterof #77 as records of another converter. A next pull request lets the model describe them.Directory.Packages.propsgets theFSharp.SystemTextJsonline that #65 adds too.🤖 Generated with Claude Code