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

Add note for xml docs + custom naming convention #4661

Merged
merged 2 commits into from
Jan 18, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,45 @@ public class CustomBatchDataLoader : BatchDataLoader<string, string?>
```

Allowing the DI to inject the options will allow the DataLoader to use the new shared pooled cache objects.

# Custom naming conventions

If you're using a custom naming convention and have xml documentation enabled, you'll need to modify the way the naming convention is hooked up
else your comments will disappear from your schema.

**v11**

```csharp
public class CustomNamingConventions : DefaultNamingConventions
{
public CustomNamingConventions()
: base() { }
}

services
.AddGraphQLServer()
.AddConvention<INamingConventions>(sp => new CustomNamingConventions()) // or
.AddConvention<INamingConventions, CustomNamingConventions>();
```

**v12**

```csharp
public class CustomNamingConventions : DefaultNamingConventions
{
public CustomNamingConventions(IDocumentationProvider documentationProvider)
: base(documentationProvider) { }
}

IReadOnlySchemaOptions capturedSchemaOptions;
services
.AddGraphQLServer()
.ModifyOptions(opt => capturedSchemaOptions = opt)
.AddConvention<INamingConventions>(sp => new CustomNamingConventions(
new XmlDocumentationProvider(
new XmlDocumentationFileResolver(
capturedSchemaOptions.ResolveXmlDocumentationFileName),
sp.GetApplicationService<ObjectPool<StringBuilder>>()
?? new NoOpStringBuilderPool())));
```

35 changes: 35 additions & 0 deletions website/src/docs/hotchocolate/defining-a-schema/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,38 @@ services
.AddGraphQLServer()
.ModifyOptions(opt => opt.UseXmlDocumentation = false);
```

## With a custom naming convention

If you want to use a custom naming convention and XML documentation, ensure you give the convention an instance of the `XmlDocumentationProvider` as demonstrated below; otherwise the comments won't appear in your schema.

```csharp
public class CustomNamingConventions : DefaultNamingConventions
{
// Before
public CustomNamingConventions()
: base() { }

// After
public CustomNamingConventions(IDocumentationProvider documentationProvider)
: base(documentationProvider) { }
}

// Startup
// Before
.AddConvention<INamingConventions>(sp => new CustomNamingConventions());

// After
IReadOnlySchemaOptions capturedSchemaOptions;

services
.AddGraphQLServer()
.ModifyOptions(opt => capturedSchemaOptions = opt)
.AddConvention<INamingConventions>(sp => new CustomNamingConventions(
new XmlDocumentationProvider(
new XmlDocumentationFileResolver(
capturedSchemaOptions.ResolveXmlDocumentationFileName),
sp.GetApplicationService<ObjectPool<StringBuilder>>()
?? new NoOpStringBuilderPool())));
```