Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben McCallum benmccallum

View GitHub Profile
@benmccallum
benmccallum / RemoveFieldsRewriter.cs
Created Jul 27, 2022
Removing fields with ITypeRewriter
View RemoveFieldsRewriter.cs
using System;
using System.Collections.Generic;
using System.Linq;
using HotChocolate.Language;
using HotChocolate.Stitching.Merge;
using HotChocolate.Stitching.Merge.Rewriters;
using HotChocolate.Types;
namespace MyCompany.GraphQLService.Stitching
{
View Annecy.md
@benmccallum
benmccallum / MergeDirectivesHandler.cs
Last active Jan 27, 2022
Hot Chocolate merge handlers for stitching
View MergeDirectivesHandler.cs
using System;
using System.Collections.Generic;
using System.Linq;
using HotChocolate.Stitching.Merge;
namespace MyCompany.GatewayService.Stitching
{
/// <summary>
/// <para>This merge handler deals with duplicate directives when schemas are stitched.</para>
/// <para>It currently handles dupes of: authorize.</para>
@benmccallum
benmccallum / README.md
Last active Jan 19, 2022
Remove internal GraphQL fields ITypeRewriter
View README.md

Removes any fields that look to be internal based on presence of "dbId" in field name or arg.

services.
  .AddGraphQLServer()
  .AddTypeRewriter(new RemoveInternalFieldsRewriter())
@benmccallum
benmccallum / OurDiagnosticEventListener.cs
Last active Aug 11, 2022
HotChocolate logging example
View OurDiagnosticEventListener.cs
using System;
using System.Collections.Generic;
using HotChocolate;
using HotChocolate.Execution;
using HotChocolate.Execution.Instrumentation;
using HotChocolate.Resolvers;
using Microsoft.Extensions.Logging;
namespace MyCompany.GraphQL.Execution.Instrumentation
{
@benmccallum
benmccallum / .readme.md
Last active Nov 18, 2021
EnumConverterUsingEnumParse
View .readme.md

A converter setup for System.Text.Json that:

  1. Deserializes numeric value or the string (member name or numeric) into the enum.
  2. Serializes out as the numeric value.
  3. Serializes out as the member name when needed as a property name (e.g. used as a dictionary key).

Helpful in transition off Newtonsoft if your clients were passing string values but you still want to serialize out as numeric. Related issue that might make this redundant: dotnet/runtime#61726

Usage: options.Converters.Add(new EnumConverterUsingEnumParseFactory());

@benmccallum
benmccallum / VerifyExtensions.cs
Created Nov 3, 2021
Verify - ScrubMatches - regex replacement with incrementing id
View VerifyExtensions.cs
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text.RegularExpressions;
namespace VerifyTests
{
public static class VerifySettingsExtensions
{
@benmccallum
benmccallum / IRazorEngineExtensions.cs
Last active Nov 3, 2021
RazorEngineCore HTML encoding with layout
View IRazorEngineExtensions.cs
using System;
using System.Collections.Generic;
using System.Linq;
using RazorEngineCore;
namespace MyCompany.Templating.RazorEngineCore
{
public static class IRazorEngineExtensions
{
// See:
@benmccallum
benmccallum / AddDbIdFieldToNodeTypesTypeInterceptor.cs
Last active Jan 21, 2022
HotChocolate Node extensions for exposing dbId
View AddDbIdFieldToNodeTypesTypeInterceptor.cs
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using HotChocolate.Configuration;
using HotChocolate.Types.Descriptors;
using HotChocolate.Types.Descriptors.Definitions;
namespace HotChocolate.Types.Relay
{
/// <summary>
@benmccallum
benmccallum / NodeResolverMiddleware.cs
Last active Jun 17, 2022
NodeResolver when stitching in Hot Chocolate
View NodeResolverMiddleware.cs
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using HotChocolate;
using HotChocolate.Execution;
using HotChocolate.Language;
using HotChocolate.Resolvers;
using HotChocolate.Stitching;