Skip to content
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 @@ -82,6 +82,7 @@ public void WriteConfigureMethod(OperationType type, IEnumerable<OperationInfo>
_writer.WriteIndentedLine("descriptor.Name({0});", GetOperationConstant(type));

var typeIndex = 0;
var operationIndex = 0;
foreach (var group in operations.GroupBy(t => t.TypeName))
{
_writer.WriteLine();
Expand All @@ -91,10 +92,61 @@ public void WriteConfigureMethod(OperationType type, IEnumerable<OperationInfo>

foreach (var operation in group)
{
var memberName = $"member{++operationIndex}";
var fieldName = $"field{operationIndex}";
var methodName = $"method{operationIndex}";
var parametersName = $"parameters{operationIndex}";

_writer.WriteIndentedLine(
"descriptor.Field({0}.GetMember(\"{1}\", bindingFlags)[0]);",
"var {0} = {1}.GetMember(\"{2}\", bindingFlags)[0];",
memberName,
typeName,
operation.MethodName);

_writer.WriteIndentedLine(
"var {0} = descriptor.Field({1});",
fieldName,
memberName);

_writer.WriteIndentedLine(
"if ({0}.IsDefined(typeof(global::HotChocolate.Types.Relay.NodeResolverAttribute), true)",
memberName);
using (_writer.IncreaseIndent())
{
_writer.WriteIndentedLine(
"&& {0} is global::System.Reflection.MethodInfo {1})",
memberName,
methodName);
}

_writer.WriteIndentedLine("{");
using (_writer.IncreaseIndent())
{
_writer.WriteIndentedLine(
"var {0} = {1}.GetParameters();",
parametersName,
methodName);
_writer.WriteIndentedLine(
"if ({0}.Length > 0)",
parametersName);
_writer.WriteIndentedLine("{");
using (_writer.IncreaseIndent())
{
_writer.WriteIndentedLine(
"{0}.Argument({1}[0].Name!, static argument =>",
fieldName,
parametersName);
using (_writer.IncreaseIndent())
{
_writer.WriteIndentedLine(
"global::HotChocolate.Types.RelayIdFieldExtensions.ID(argument));");
}
}

_writer.WriteIndentedLine("}");
}

_writer.WriteIndentedLine("}");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using HotChocolate.Execution;
using Microsoft.Extensions.DependencyInjection;

namespace HotChocolate.Types;

public class Issue8057ProbeTests
{
[Fact]
public async Task NodeResolver_And_Query_On_Same_Method_With_Strongly_Typed_Id_Does_Not_Throw()
{
var exception = await Record.ExceptionAsync(
async () => await new ServiceCollection()
.AddGraphQLServer(disableDefaultSecurity: true)
.AddIntegrationTestTypes()
.AddGlobalObjectIdentification()
.BuildSchemaAsync());

Assert.Null(exception);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using HotChocolate.Resolvers;
using HotChocolate.Types.Relay;

namespace HotChocolate.Types;

[Node]
public sealed class Issue8057Entity
{
[ID(nameof(Issue8057Entity))]
public Issue8057EntityId Id { get; init; }
}

public readonly struct Issue8057EntityId;

public static class Issue8057EntityOperations
{
[NodeResolver]
[Query]
public static Issue8057Entity? GetIssue8057Entity(
Issue8057EntityId id,
IResolverContext resolverContext)
=> new() { Id = id };
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ schema {
query: Query
}

"The node interface is implemented by entities that have a global unique identifier."
interface Node {
id: ID!
}

interface Product {
kind: String!
id: String!
Expand All @@ -13,6 +18,10 @@ type Book implements Product {
kind: String!
}

type Issue8057Entity implements Node {
id: ID!
}

"Information about pagination in a connection."
type PageInfo {
"Indicates whether more edges exist following the set defined by the clients arguments."
Expand Down Expand Up @@ -46,8 +55,8 @@ type ProductsEdge {
type Query {
"""
Gets the product.


**Returns:**
The only product.
"""
Expand All @@ -63,6 +72,7 @@ type Query {
listArgumentRef(items: [String!]!): String!
listNullableElementArgumentRef(items: [String]!): String!
nullableListNullableElementArgumentRef(items: [String]): String!
issue8057Entity(id: ID!): Issue8057Entity @cost(weight: "10")
}

type Television implements Product {
Expand Down
Loading