private static bool GetOnFragment(IResolverContext context) { IReadOnlyCollection <DirectiveLocation> locations = context.Parent <Directive>().Locations; return(Contains(locations, DirectiveLocation.InlineFragment) || Contains(locations, DirectiveLocation.FragmentSpread) || Contains(locations, DirectiveLocation.FragmentDefinition)); }
private static bool GetOnOperation(IResolverContext context) { IReadOnlyCollection <DirectiveLocation> locations = context.Parent <Directive>().Locations; return(Contains(locations, DirectiveLocation.Query) || Contains(locations, DirectiveLocation.Mutation) || Contains(locations, DirectiveLocation.Subscription)); }
public VariableValue Resolve( IResolverContext context, ScopedVariableNode variable, IInputType targetType) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (variable == null) { throw new ArgumentNullException(nameof(variable)); } if (!ScopeNames.Fields.Equals(variable.Scope.Value)) { throw new ArgumentException( FieldScopedVariableResolver_CannotHandleVariable, nameof(variable)); } if (context.ObjectType.Fields.TryGetField(variable.Name.Value, out IObjectField? field)) { object parent = context.Parent <object>(); IValueNode?valueLiteral = null; if (parent is IReadOnlyDictionary <string, object> dict && dict.TryGetValue(field.Name, out object?value)) { if (value is IValueNode v) { valueLiteral = v; } else if (field.Type.IsInputType() && field.Type is IInputType type) { valueLiteral = type.ParseValue(value); } } return(new VariableValue ( variable.ToVariableName(), targetType.ToTypeNode(), valueLiteral ?? NullValueNode.Default, null )); } throw ThrowHelper.FieldScopedVariableResolver_InvalidFieldName( variable.Name.Value, context.Selection.SyntaxNode, context.Path); }
public static double GetHeight( IResolverContext context) { double height = context.Parent <ICharacter>().Height; if (context.Argument <Unit?>("unit") == Unit.Foot) { return(height * 3.28084d); } return(height); }
public static async Task <IEnumerable <Comment> > GetComments(IResolverContext context) { var post = context.Parent <Post>(); var first = context.Argument <int>("first"); var offset = context.Argument <int>("offset"); return(await context .Service <ICommentQuery>() .WithPost(post.CanonicalTitle) .Fetch(first, offset)); }
private static long GetTotalCount( IResolverContext context) { IConnection connection = context.Parent <IConnection>(); if (connection.PageInfo.TotalCount.HasValue) { return(connection.PageInfo.TotalCount.Value); } throw new GraphQLException( "The total count was not provided by the connection."); }
private static IResolverResult <long> GetTotalCount( IResolverContext context) { IConnection connection = context.Parent <IConnection>(); if (connection.PageInfo.TotalCount.HasValue) { return(ResolverResult.CreateValue( connection.PageInfo.TotalCount.Value)); } return(ResolverResult.CreateError <long>( "The total count was not provided by the connection.")); }
public static IEnumerable <ICharacter> GetCharacter( IResolverContext context) { ICharacter character = context.Parent <ICharacter>(); CharacterRepository repository = context.Service <CharacterRepository>(); foreach (string friendId in character.Friends) { ICharacter friend = repository.GetCharacter(friendId); if (friend != null) { yield return(friend); } } }
public VariableValue Resolve( IResolverContext context, ScopedVariableNode variable, IInputType targetType) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (variable == null) { throw new ArgumentNullException(nameof(variable)); } if (!ScopeNames.Fields.Equals(variable.Scope.Value)) { throw new ArgumentException( StitchingResources .FieldScopedVariableResolver_CannotHandleVariable, nameof(variable)); } if (context.ObjectType.Fields.TryGetField(variable.Name.Value, out ObjectField field)) { IReadOnlyDictionary <string, object> obj = context.Parent <IReadOnlyDictionary <string, object> >(); return(new VariableValue ( variable.ToVariableName(), targetType.ToTypeNode(), _converter.Convert(obj[field.Name], targetType, variable.Value), null )); } throw new QueryException(ErrorBuilder.New() .SetMessage( StitchingResources.FieldScopedVariableResolver_InvalidFieldName, variable.Name.Value) .SetCode(ErrorCodes.FieldNotDefined) .SetPath(context.Path) .AddLocation(context.FieldSelection) .Build()); }
public VariableValue Resolve( IResolverContext context, ScopedVariableNode variable, ITypeNode targetType) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (variable == null) { throw new ArgumentNullException(nameof(variable)); } if (!ScopeNames.Fields.Equals(variable.Scope.Value)) { throw new ArgumentException( StitchingResources .FieldScopedVariableResolver_CannotHandleVariable, nameof(variable)); } if (context.ObjectType.Fields.TryGetField(variable.Name.Value, out ObjectField field)) { IReadOnlyDictionary <string, object> obj = context.Parent <IReadOnlyDictionary <string, object> >(); return(new VariableValue ( variable.ToVariableName(), field.Type.ToTypeNode(), obj[field.Name], null )); } throw new QueryException(QueryError.CreateFieldError( string.Format(CultureInfo.InvariantCulture, StitchingResources .FieldScopedVariableResolver_InvalidFieldName, variable.Name.Value), context.Path, context.FieldSelection) .WithCode(ErrorCodes.FieldNotDefined)); }
public T Parent <T>() => _resolverContext.Parent <T>();
public void ResolverContext(IResolverContext context) { _context = context; Id = context.Parent <Property>().Id; Last = context.Argument <int?>("last"); }