我想alarms
在我的服务器应用程序上注册。为了防止传递 10 多个参数,我alarm
在客户端序列化我的并将其传递List<JSONString>
给我的服务器。反序列化它,注册它并给出已注册的答案alarm
。
现在我的问题是,我不知道如何传递这些参数:
使用突变 - DictionaryType
"类型为 \"[String]!\" 的变量 \"$params\" 用于期望类型 \"[DictionaryType]!\" 的位置。"
使用突变 - StringGraphType
“无法将值转换为 AST:System.Collections.Generic.Dictionary`2[System.String,System.Object]”,**
服务器
突变 - DictionaryType
public class Mutation : ObjectGraphType
{
public Mutation()
{
Name = "Mutation";
FieldAsync<HtStaticAlarmBaseType>(
"registerStaticAlarms",
"Register a list with static alarms.",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<ListGraphType<DictionaryType>>> {Name = "params"}
),
resolve: async context =>
{
List<object> parameterString = context.GetArgument<List<object>>("params");
//TODO
return null;
}
);
}
}
突变 - DictionaryType
public class Mutation : ObjectGraphType
{
public Mutation()
{
Name = "Mutation";
FieldAsync<HtStaticAlarmBaseType>(
"registerStaticAlarms",
"Register a list with static alarms.",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<ListGraphType<StringGraphType>>> {Name = "params"}
),
resolve: async context =>
{
List<object> parameterString = context.GetArgument<List<object>>("params");
//TODO
return null;
}
);
}
}
字典类型
public class DictionaryType : ObjectGraphType<Dictionary<string,string>>
{
public DictionaryType()
{
Name = "DictionaryType";
Description = "Dictionary of type string, string.";
}
}
HtStaticAlarmBaseType
public class HtStaticAlarmBaseType : ObjectGraphType<HtStaticAlarmBase>
{
public HtStaticAlarmBaseType()
{
Name = "HtStaticAlarmBase";
Description = "Base class of a static alarm.";
// ##################################################
// HtAlarmBase
// ##################################################
#region HtAlarmBase
Field<StringGraphType>(
"AlarmClass",
resolve: context => context.Source.AlarmClass.ToString());
Field<StringGraphType>(
"AlarmGroup",
resolve: context => context.Source.AlarmGroup);
Field<IntGraphType>(
"ErrorCode",
resolve: context => (int)context.Source.ErrorCode);
Field<StringGraphType>(
"Id",
resolve: context => context.Source.Id.ToString());
Field<StringGraphType>(
"Message",
resolve: context => context.Source.Message);
Field<StringGraphType>(
"Station",
resolve: context => context.Source.Station);
Field<StringGraphType>(
"TimeStampCome",
resolve: context => context.Source.TimeStampCome?.ToString());
Field<StringGraphType>(
"TimeStampGone",
resolve: context => context.Source.TimeStampGone?.ToString());
Field<StringGraphType>(
"TimeStampAcknowledge",
resolve: context => context.Source.TimeStampAcknowledge?.ToString());
Field<StringGraphType>(
"Origin",
resolve: context => context.Source.Origin);
#endregion
Field<IntGraphType>(
"Number",
resolve: context => context.Source.Number);
Field<BooleanGraphType>(
"Active",
resolve: context => context.Source.Active);
}
}