Skip to content

Commit

Permalink
Update Id Serialization documentation
Browse files Browse the repository at this point in the history
Updated V14 and V15 documeation for Id Serialization.
Updated article component to correctly reference the main branch instead of the removed master branch.
  • Loading branch information
solvticians-be committed Jan 6, 2025
1 parent 233220e commit b97f9cd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion website/src/components/articles/doc-article-community.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const DocArticleCommunity: FC<DocArticleCommunityProps> = ({
originPath,
}) => {
const metadata = data.site!.siteMetadata!;
const docPath = `${metadata.repositoryUrl!}/blob/master/website/src/docs/${originPath}`;
const docPath = `${metadata.repositoryUrl!}/blob/main/website/src/docs/${originPath}`;

return (
<Container>
Expand Down
14 changes: 8 additions & 6 deletions website/src/docs/hotchocolate/v14/defining-a-schema/relay.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,29 @@ The approach of either implementation-first or code-first can be used in conjunc

## Id Serializer

Unique (or global) Ids are generated using the `IIdSerializer`. We can access it like any other service and use it to serialize or deserialize global Ids ourselves.
Unique (or global) Ids are generated using the `DefaultNodeIdSerializer`. We can access it like any other service and use it to serialize or deserialize global Ids ourselves.

```csharp
public class Query
{
public string Example(IIdSerializer serializer)
public string Example(DefaultNodeIdSerializer serializer)
{
string serializedId = serializer.Serialize(null, "Product", "123");
string serializedId = serializer.Format("Product", "123");

IdValue deserializedIdValue = serializer.Deserialize(serializedId);
object deserializedId = deserializedIdValue.Value;
NodeId deserializedIdValue = serializer.Parse(serializedId, typeof(Int32));
object deserializedId = deserializedIdValue.InternalId;

// Omitted code for brevity
}
}
```

The `Serialize()` method takes the schema name as a first argument, followed by the type name and lastly the actual Id.
The `Format()` method takes the type name as a first argument, followed by the actual Id.

[Learn more about accessing services](/docs/hotchocolate/v14/fetching-data/resolvers#injecting-services)

> Note: `OptimizedNodeIdSerializer` and `LegacyNodeIdSerializer` can also be used in the above example as serializers.
# Complex Ids

In certain situations, you may need to use complex identifiers for your data models, rather than simple integers or strings. HotChocolate provides support for complex IDs by allowing you to define custom ID types, which can be used in your GraphQL schema.
Expand Down
13 changes: 8 additions & 5 deletions website/src/docs/hotchocolate/v15/defining-a-schema/relay.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,30 @@ The approach of either implementation-first or code-first can be used in conjunc

## Id Serializer

Unique (or global) Ids are generated using the `IIdSerializer`. We can access it like any other service and use it to serialize or deserialize global Ids ourselves.
Unique (or global) Ids are generated using the `DefaultNodeIdSerializer`. We can access it like any other service and use it to serialize or deserialize global Ids ourselves.


```csharp
public class Query
{
public string Example(IIdSerializer serializer)
{
string serializedId = serializer.Serialize(null, "Product", "123");
string serializedId = serializer.Format("Product", "123");

IdValue deserializedIdValue = serializer.Deserialize(serializedId);
object deserializedId = deserializedIdValue.Value;
NodeId deserializedIdValue = serializer.Parse(serializedId, typeof(Int32));
object deserializedId = deserializedIdValue.InternalId;

// Omitted code for brevity
}
}
```

The `Serialize()` method takes the schema name as a first argument, followed by the type name and lastly the actual Id.
The `Format()` method takes the type name as a first argument, followed by the actual Id.

[Learn more about accessing services](/docs/hotchocolate/v15/fetching-data/resolvers#injecting-services)

> Note: `OptimizedNodeIdSerializer` and `LegacyNodeIdSerializer` can also be used in the above example as serializers.
# Complex Ids

In certain situations, you may need to use complex identifiers for your data models, rather than simple integers or strings. HotChocolate provides support for complex IDs by allowing you to define custom ID types, which can be used in your GraphQL schema.
Expand Down

0 comments on commit b97f9cd

Please sign in to comment.