本文整理汇总了C#中Fields.First方法的典型用法代码示例。如果您正苦于以下问题:C# Fields.First方法的具体用法?C# Fields.First怎么用?C# Fields.First使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fields
的用法示例。
在下文中一共展示了Fields.First方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveField
public async Task<object> ResolveField(ExecutionContext context, ObjectGraphType parentType, object source, Fields fields)
{
context.CancellationToken.ThrowIfCancellationRequested();
var field = fields.First();
var fieldDefinition = GetFieldDefinition(context.Schema, parentType, field);
if (fieldDefinition == null)
{
return null;
}
var arguments = GetArgumentValues(context.Schema, fieldDefinition.Arguments, field.Arguments, context.Variables);
Func<ResolveFieldContext, object> defaultResolve = (ctx) =>
{
return ctx.Source != null ? GetProperyValue(ctx.Source, ctx.FieldAst.Name) : null;
};
try
{
var resolveContext = new ResolveFieldContext();
resolveContext.FieldAst = field;
resolveContext.FieldDefinition = fieldDefinition;
resolveContext.Schema = context.Schema;
resolveContext.ParentType = parentType;
resolveContext.Arguments = arguments;
resolveContext.Source = source;
resolveContext.CancellationToken = context.CancellationToken;
var resolve = fieldDefinition.Resolve ?? defaultResolve;
var result = resolve(resolveContext);
if(result is Task)
{
var task = result as Task;
await task;
result = GetProperyValue(task, "Result");
}
if (parentType is __Field && result is Type)
{
result = context.Schema.FindType(result as Type);
}
return await CompleteValue(context, context.Schema.FindType(fieldDefinition.Type), fields, result);
}
catch (Exception exc)
{
context.Errors.Add(new ExecutionError("Error trying to resolve {0}.".ToFormat(field.Name), exc));
return null;
}
}
示例2: ResolveField
public object ResolveField(ExecutionContext context, ObjectGraphType parentType, object source, Fields fields)
{
var field = fields.First();
var fieldDefinition = GetFieldDefinition(context.Schema, parentType, field);
if (fieldDefinition == null)
{
return null;
}
var arguments = GetArgumentValues(fieldDefinition.Arguments, field.Arguments, context.Variables);
Func<ResolveFieldContext, object> defaultResolve = (ctx) =>
{
return ctx.Source != null ? GetProperyValue(ctx.Source, ctx.FieldAst.Name) : null;
};
try
{
var resolveContext = new ResolveFieldContext();
resolveContext.FieldAst = field;
resolveContext.FieldDefinition = fieldDefinition;
resolveContext.Schema = context.Schema;
resolveContext.ParentType = parentType;
resolveContext.Arguments = arguments;
resolveContext.Source = source;
var resolve = fieldDefinition.Resolve ?? defaultResolve;
var result = resolve(resolveContext);
return CompleteValue(context, fieldDefinition.Type, fields, result);
}
catch (Exception exc)
{
context.Errors.Add(new ExecutionError("Error trying to resolve {0}.".ToFormat(field.Name), exc));
return null;
}
}
示例3: ResolveFieldAsync
public async Task<ResolveFieldResult<object>> ResolveFieldAsync(ExecutionContext context, IObjectGraphType parentType, object source, Fields fields)
{
context.CancellationToken.ThrowIfCancellationRequested();
var resolveResult = new ResolveFieldResult<object>
{
Skip = false
};
var field = fields.First();
var fieldDefinition = GetFieldDefinition(context.Schema, parentType, field);
if (fieldDefinition == null)
{
resolveResult.Skip = true;
return resolveResult;
}
var arguments = GetArgumentValues(context.Schema, fieldDefinition.Arguments, field.Arguments, context.Variables);
try
{
var resolveContext = new ResolveFieldContext();
resolveContext.FieldName = field.Name;
resolveContext.FieldAst = field;
resolveContext.FieldDefinition = fieldDefinition;
resolveContext.ReturnType = fieldDefinition.ResolvedType;
resolveContext.ParentType = parentType;
resolveContext.Arguments = arguments;
resolveContext.Source = source;
resolveContext.Schema = context.Schema;
resolveContext.Document = context.Document;
resolveContext.Fragments = context.Fragments;
resolveContext.RootValue = context.RootValue;
resolveContext.UserContext = context.UserContext;
resolveContext.Operation = context.Operation;
resolveContext.Variables = context.Variables;
resolveContext.CancellationToken = context.CancellationToken;
resolveContext.Metrics = context.Metrics;
var resolver = fieldDefinition.Resolver ?? new NameFieldResolver();
var result = resolver.Resolve(resolveContext);
if (result is Task)
{
var task = result as Task;
await task.ConfigureAwait(false);
result = task.GetProperyValue("Result");
}
resolveResult.Value =
await CompleteValueAsync(context, fieldDefinition.ResolvedType, fields, result).ConfigureAwait(false);
return resolveResult;
}
catch (Exception exc)
{
var error = new ExecutionError("Error trying to resolve {0}.".ToFormat(field.Name), exc);
error.AddLocation(field, context.Document);
context.Errors.Add(error);
resolveResult.Skip = false;
return resolveResult;
}
}
示例4: ResolveFieldAsync
public async Task<ResolveFieldResult<object>> ResolveFieldAsync(ExecutionContext context, ObjectGraphType parentType, object source, Fields fields)
{
context.CancellationToken.ThrowIfCancellationRequested();
var resolveResult = new ResolveFieldResult<object>
{
Skip = false
};
var field = fields.First();
var fieldDefinition = GetFieldDefinition(context.Schema, parentType, field);
if (fieldDefinition == null)
{
resolveResult.Skip = true;
return resolveResult;
}
var arguments = GetArgumentValues(context.Schema, fieldDefinition.Arguments, field.Arguments, context.Variables);
Func<ResolveFieldContext, object> defaultResolve =
ctx => ctx.Source != null
? GetProperyValue(ctx.Source, ctx.FieldAst.Name)
: null;
try
{
var resolveContext = new ResolveFieldContext();
resolveContext.FieldName = field.Name;
resolveContext.FieldAst = field;
resolveContext.FieldDefinition = fieldDefinition;
resolveContext.ReturnType = context.Schema.FindType(fieldDefinition.Type);
resolveContext.ParentType = parentType;
resolveContext.Arguments = arguments;
resolveContext.Source = source;
resolveContext.Schema = context.Schema;
resolveContext.Fragments = context.Fragments;
resolveContext.RootValue = context.RootValue;
resolveContext.Operation = context.Operation;
resolveContext.Variables = context.Variables;
resolveContext.CancellationToken = context.CancellationToken;
var resolve = fieldDefinition.Resolve ?? defaultResolve;
var result = resolve(resolveContext);
if(result is Task)
{
var task = result as Task;
await task.ConfigureAwait(false);
result = GetProperyValue(task, "Result");
}
if (parentType is __Field && result is Type)
{
result = context.Schema.FindType(result as Type);
}
resolveResult.Value = await CompleteValueAsync(context, context.Schema.FindType(fieldDefinition.Type), fields, result).ConfigureAwait(false);
return resolveResult;
}
catch (Exception exc)
{
var error = new ExecutionError("Error trying to resolve {0}.".ToFormat(field.Name), exc);
error.AddLocation(field.SourceLocation.Line, field.SourceLocation.Column);
context.Errors.Add(error);
resolveResult.Skip = false;
return resolveResult;
}
}