GraphQL HotChocolate 中 Url/Uri 的语法是什么?

What is the syntax for a Url/Uri in GraphQL HotChocolate?

我正在用 C# 中的 Uri 类型的参数编写 GraphQL 查询。当输入“http://dotnetperls.com/”的值时,它告诉我类型错误。有谁知道这应该是什么格式才能符合 GraphQL?

映射到Uri的HotChocolate Scalar Types list contains a UrlType。 将您的参数声明为 UrlType 类型就足够了。 根据您使用的 HotChocolate 版本,框架可能会自动键入参数,否则,您可以在 QueryType 配置中覆盖参数类型:

public class QueryType: ObjectType<Query>
{
    protected override void Configure(IObjectTypeDescriptor<Query> descriptor)
    {
         [...]
         descriptor.Field(t => t.GetMyEntity(default))
            .Argument("myArgument", a => a.Type<NonNullType<UrlType>>());
         [...]
    }
}

编辑:在 9.0.0 版本以下,您将需要注册扩展标量类型,如图所示 here