Scalars are created as instances of ScalarType.


These are provided as static properties on ScalarType.

  • ScalarType.Boolean
  • ScalarType.Int
  • ScalarType.ID
  • ScalarType.Float
  • ScalarType.String

In addition following non-null instances are provided for convenience.

  • ScalarType.NonNullBoolean
  • ScalarType.NonNullInt
  • ScalarType.NonNullID
  • ScalarType.NonNullFloat
  • ScalarType.NonNullString

Also standard collection is provided

Standard =
            new List<(ScalarType Type, IValueConverter Converter)>()
                (String, new StringConverter()),
                (Int, new IntConverter()),
                (Float, new DoubleConverter()),
                (Boolean, new BooleanConverter()),
                (ID, new IdConverter())

Custom scalars

Create instance of ScalarType and provide name and metadata. Value converter is also needed when building schema with custom scalar in it.



ID = new ScalarType(
            "The ID scalar type represents a unique identifier, often used to refetch an object" +
            " or as the key for a cache. The ID type is serialized in the same way as a String; " +
            "however, it is not intended to be human‐readable. While it is often numeric, it " +
            "should always serialize as a String.")


    public class IdConverter : IValueConverter
        public object Serialize(object value)
            if (value == null)
                return null;

            return Convert.ToString(value, CultureInfo.InvariantCulture);

        public object ParseValue(object input)
            if (input == null)
                return null;

            return Convert.ToString(input, CultureInfo.InvariantCulture);

        public object ParseLiteral(GraphQLScalarValue input)
            if (input.Kind == ASTNodeKind.NullValue)
                return null;

            if (input.Kind == ASTNodeKind.StringValue) 
                return input.Value;

            throw new FormatException(
                $"Cannot coerce Long value from '{input.Kind}'");