Skip to content

feat(gremlin): describe how a record is stored in a graph - #76

Open
xperiandri wants to merge 2 commits into
mainfrom
feat/gremlin-graph-model
Open

xperiandri wants to merge 2 commits into
mainfrom
feat/gremlin-graph-model

Conversation

@xperiandri

@xperiandri xperiandri commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

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. GraphModel gives 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 into main, so the base is main. After #75 merges, I rebase this branch.

What the model gives

  • GraphModel.create options serializerOptions reads the options of the serializer one time, and gives the model or the reasons why it cannot work with them.
  • VertexOf, EdgeOf and MetaOf give 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 field Id, 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 (a VertexProperty) or WithMetaList.
  • PartitionKeyModel: with GraphModelOptions.PartitionKeyProperty (Azure Cosmos DB), the field with [<PartitionKey>] or the field with that name (also Id) gives the partition key, for SkillGro CompanyId for the property PartitionKey. 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

  • Options: not one converter of FSharp.SystemTextJson of that class, not every kind of type, no UnwrapOption, IncludeRecordProperties, WithOverrideMembers, references, numbers as texts, ignored read-only members; a partition key property that is empty, has a slash, or is id or label.
  • Records: a class, an anonymous record, a record that another converter writes (also a record converter before the one of FSharp.SystemTextJson) or that has options of its own, a public property with JsonInclude, a generic record without [<Label>], an empty label, a naming policy that gives Value and Meta of VertexProperty one name.
  • Fields: an object, a dictionary, a map, a tuple, a type that the options cannot write, an option of an option, Nullable (declare a voption), an optional list, a list of options or of lists, the names id and label, 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.
  • Ids and partition keys: a vertex without Id, an optional or list id of a vertex, no partition key, two of them, or one that is optional or ignored.
  • Edges: a list, a vertex property, a partition key (Azure Cosmos DB keeps an edge in the partition of its out-vertex).
  • A field of a value type with [<JsonIgnore>]: FSharp.SystemTextJson 1.4.36 throws NullReferenceException when 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.
  • I planted defects: I changed the model in 80 small, incorrect ways, one change at a time, and ran the tests after each change. In the first run, one change survived: two meta-properties with one name. A new test refuses it, and now all 80 changes make a test fail.
  • No warning in the new files, no escaped tags in the XML documentation, Fantomas accepts the files.

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 AllowNullFSharpRecordConverter of #77 as records of another converter. A next pull request lets the model describe them. Directory.Packages.props gets the FSharp.SystemTextJson line that #65 adds too.

🤖 Generated with Claude Code

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>
@xperiandri
xperiandri requested a balanced review from Copilot November 8, 2026 03:00
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The pull request adds FSharp.Gremlin graph-model APIs and serializer-profile validation, plus FSharp.Azure.Cosmos.Gremlin connection settings for Azure and emulator endpoints. It adds test projects, tests, and solution configuration for both libraries.

Changes: Gremlin support

Layer / File(s) Summary
Gremlin contracts and serializer profile
src/Gremlin/*, Directory.Packages.props, FSharp.Azure.Cosmos.slnx, FSharp.Azure.Cosmos.slnf, .github/copilot-instructions.md
Adds graph-model types, attributes, vertex-property APIs, and serializer-profile validation. Adds the Gremlin project and package reference to the solution configuration.
Graph-model construction and validation
src/Gremlin/GraphModel.fs, tests/Gremlin.Tests/*, tests/Gremlin.Tests/GraphModel/*, .github/instructions/test-layout.instructions.md
Adds model creation and caching for record types, with validation of graph shapes, partition keys, labels, names, and serializer settings. Tests cover supported models, refusal cases, and serializer profiles.
Cosmos Gremlin connection settings
src/Cosmos.Gremlin/*, tests/Cosmos.Gremlin.Tests/*, .github/copilot-instructions.md, .github/instructions/test-layout.instructions.md
Adds Azure and emulator connection constructors with input validation. Tests cover endpoint settings, resource IDs, account names, and key omission from connection text.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant GraphModel
  participant SerializerProfile
  participant GraphModelBuilder
  Caller->>GraphModel: create(options, serializerOptions)
  GraphModel->>SerializerProfile: validate serializer options
  SerializerProfile-->>GraphModel: profile or refusals
  Caller->>GraphModel: VertexOf(recordType)
  GraphModel->>GraphModelBuilder: build model when not cached
  GraphModelBuilder-->>GraphModel: element model
  GraphModel-->>Caller: cached element model
Loading
Merge Risk: Minimal · up to 63c63

This change adds new Gremlin graph-model and Cosmos connection-settings libraries with tests. No concrete merge-blocking risk was found in the supplied evidence.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat(gremlin): describe how a record is stored in a graph" matches the main change. The PR adds GraphModel, which describes how F# records map to Gremlin vertices, edges, and meta-propertie…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(gremlin): describe how a record is stored in a graph" matches the main change. The PR adds GraphModel, which describes how F# records map to Gremlin vertices, edges, and meta-properties (labels, IDs, partition keys, property names and shapes). The title is short, specific, and follows a conventional-commit style. It does not mention the new projects, attributes, or VertexProperty type, but the title does not need to cover every detail.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 318060c6-7923-4323-a9cb-cacfa0c206f4
Commits

Reviewing files that changed from the base of the PR and between ef5d60b and 63c63fd.

Files selected for processing: 29

  • .github/copilot-instructions.md
  • .github/instructions/test-layout.instructions.md
  • Directory.Packages.props
  • FSharp.Azure.Cosmos.slnf
  • FSharp.Azure.Cosmos.slnx
  • src/Cosmos.Gremlin/AssemblyInfo.fs
  • src/Cosmos.Gremlin/CosmosGremlinConnection.fs
  • src/Cosmos.Gremlin/FSharp.Azure.Cosmos.Gremlin.fsproj
  • src/Gremlin/AssemblyInfo.fs
  • src/Gremlin/Attributes.fs
  • src/Gremlin/ElementModel.fs
  • src/Gremlin/FSharp.Gremlin.fsproj
  • src/Gremlin/GraphModel.fs
  • src/Gremlin/GraphModelException.fs
  • src/Gremlin/SerializerProfile.fs
  • src/Gremlin/VertexProperty.fs
  • tests/Cosmos.Gremlin.Tests/CosmosGremlinConnectionTests.fs
  • tests/Cosmos.Gremlin.Tests/FSharp.Azure.Cosmos.Gremlin.Tests.fsproj
  • tests/Cosmos.Gremlin.Tests/TestCategories.fs
  • tests/Cosmos.Gremlin.Tests/testconfig.json
  • tests/Gremlin.Tests/FSharp.Gremlin.Tests.fsproj
  • tests/Gremlin.Tests/GraphModel/AttributeTests.fs
  • tests/Gremlin.Tests/GraphModel/GraphModelTests.fs
  • tests/Gremlin.Tests/GraphModel/SerializerProfileTests.fs
  • tests/Gremlin.Tests/GraphModel/VertexPropertyTests.fs
  • tests/Gremlin.Tests/GraphRecords.fs
  • tests/Gremlin.Tests/Profiles.fs
  • tests/Gremlin.Tests/TestCategories.fs
  • tests/Gremlin.Tests/testconfig.json

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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
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

Comment thread src/Gremlin/GraphModel.fs Resolved
Comment thread src/Gremlin/GraphModel.fs Resolved
Comment thread src/Gremlin/GraphModel.fs Resolved
Comment thread src/Gremlin/GraphModel.fs Resolved
Comment thread src/Gremlin/SerializerProfile.fs Resolved
Comment thread src/Gremlin/SerializerProfile.fs Resolved
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/Gremlin/GraphModel.fs
Comment on lines +425 to +426
if not (names.Add property.Name) then
refuseField recordType role property.Member $"another field has the name {property.Name} too."
Comment thread src/Gremlin/GraphModel.fs

// 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
Comment thread src/Gremlin/GraphModel.fs
Comment on lines +342 to +354
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
Comment thread src/Gremlin/GraphModel.fs
->
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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants