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

Fixes Interface Field Naming Convention. #5158

Merged
merged 2 commits into from
Jun 14, 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 @@ -39,13 +39,13 @@ protected internal InterfaceFieldDescriptor(

Definition.Name = context.Naming.GetMemberName(
member,
MemberKind.InputObjectField);
MemberKind.InterfaceField);
Definition.Description = context.Naming.GetMemberDescription(
member,
MemberKind.InputObjectField);
MemberKind.InterfaceField);
Definition.Type = context.TypeInspector.GetOutputReturnTypeRef(member);

if (context.Naming.IsDeprecated(member, out string reason))
if (context.Naming.IsDeprecated(member, out var reason))
{
Deprecated(reason);
}
Expand Down
40 changes: 40 additions & 0 deletions src/HotChocolate/Core/test/Types.Tests/Types/InterfaceTypeTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using HotChocolate.Execution;
using HotChocolate.Language;
using HotChocolate.Tests;
using HotChocolate.Types.Descriptors;
using Microsoft.Extensions.DependencyInjection;
using Snapshooter.Xunit;
Expand Down Expand Up @@ -726,6 +729,43 @@ type Foo implements Interface {
ex.Errors[0].ToString().MatchSnapshot();
}

[Fact]
public async Task Ensure_Interface_Field_Is_Requested_When_Applying_NamingConvention()
{
await new ServiceCollection()
.AddGraphQL()
.AddConvention<INamingConventions, SnakeCaseNamingConventions>()
.AddQueryType(x => x
.Name("Query")
.Field("foo")
.Type<InterfaceType<IFooNaming>>()
.Resolve(() => null))
.AddResolver("Foo", "bar", x => 1)
.ModifyOptions(o => o.StrictValidation = false)
.BuildSchemaAsync()
.MatchSnapshotAsync();
}

private sealed class SnakeCaseNamingConventions : DefaultNamingConventions
{
public override NameString GetMemberName(MemberInfo member, MemberKind kind)
{
if (kind == MemberKind.InterfaceField)
{
var pattern = new Regex(
@"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+");
return string.Join("_", pattern.Matches(member.Name)).ToLower();
}

return base.GetMemberName(member, kind);
}
}

private interface IFooNaming
{
string FooBarBaz { get; }
}

public interface IFoo
{
bool Bar { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
schema {
query: Query
}

interface IFooNaming {
foo_bar_baz: String
}

type Query {
foo: IFooNaming
}

"The `@defer` directive may be provided for fragment spreads and inline fragments to inform the executor to delay the execution of the current fragment to indicate deprioritization of the current fragment. A query with `@defer` directive will cause the request to potentially return multiple responses, where non-deferred data is delivered in the initial response and data deferred is delivered in a subsequent response. `@include` and `@skip` take precedence over `@defer`."
directive @defer("If this argument label has a value other than null, it will be passed on to the result of this defer directive. This label is intended to give client applications a way to identify to which fragment a deferred result belongs to." label: String "Deferred when true." if: Boolean) on FRAGMENT_SPREAD | INLINE_FRAGMENT

"The `@stream` directive may be provided for a field of `List` type so that the backend can leverage technology such as asynchronous iterators to provide a partial list in the initial response, and additional list items in subsequent responses. `@include` and `@skip` take precedence over `@stream`."
directive @stream("If this argument label has a value other than null, it will be passed on to the result of this stream directive. This label is intended to give client applications a way to identify to which fragment a streamed result belongs to." label: String "The initial elements that shall be send down to the consumer." initialCount: Int! = 0 "Streamed when true." if: Boolean) on FIELD