1

I'm writing a GraphQL query with a parameter that has a type of Uri in C#. When entering a value of "http://dotnetperls.com/" it tells me the type is wrong. Does anyone know what format this should be in to conform with GraphQL?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Tristan Trainer
  • 2,770
  • 2
  • 17
  • 33

1 Answers1

1

The HotChocolate Scalar Types list contains a UrlType which maps to Uri. Declaring your argument to be of type UrlType should be sufficient. Depending on the version of HotChocolate you are using, the framework might type the argument automatically, otherwise, you can override your argument's type in your QueryType configuration:

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>>());
         [...]
    }
}

Edit: below version 9.0.0 you will need to register the extended scalar types as shown here.

misraoui
  • 56
  • 3
  • From version 9 on we are able to auto-detect which extend scalar you actually want to use. You can change that behavior by altering the default bindings through the 'SchemaBuilder' with `BindClrType`. – Michael Ingmar Staib Jul 18 '19 at 12:03