Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Id Serialization documentation #7903

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading