internal QueryBuilder(ObjectGraphType <object> objectGraphType, string queryName, string description, IGraphQlRepositoryProvider graphQlRepositoryProvider, IDistributedCache distributedCache, ILogger logger, IConnectionEdgeHandler connectionEdgeHandler, IInMemoryComparerProvider inMemoryComparerProvider, IModelMemberQueryArgumentProvider modelMemberQueryArgumentProvider, IContextValueResolver contextValueResolver) { _objectGraphType = objectGraphType; _queryName = queryName; _description = description; _queryExecutor = new QueryExecutor <TSource>(graphQlRepositoryProvider, logger, connectionEdgeHandler); _distributedCache = distributedCache; _logger = logger; _modelMemberQueryArgumentProvider = modelMemberQueryArgumentProvider; _queryParameterBuilder = new QueryParameterBuilder <TSource>(this, inMemoryComparerProvider, contextValueResolver); }
/// <summary> /// Creates a new instance of SearchQueryBuilder. /// </summary> /// <typeparam name="TSource">Search source type.</typeparam> /// <param name="qb">QueryBuilder instance.</param> /// <returns>QueryStepBuilder.</returns> private static QueryStepBuilder <TSource, SearchModel> Create <TSource>(QueryParameterBuilder <TSource> qb) { var step = new QueryStepBuilder <TSource, SearchModel>(qb); step.DisableConnectionEdgeCheck(); step.OverrideRepositoryTypeWith <SearchResult>(); step.AddStepBagItem(SearchConstants.QueryName, qb.GetQueryBuilderQueryName()); step.WithProperty(x => x.SearchText); step.AddQueryExecutionContextInterceptor(ctx => { // This step is for backwards compatibility. var searchResults = ctx.GetQueryResults <SearchResult>(); var list = new List <SearchResultModel>(); searchResults.ForEach(sr => list.AddRange(sr.Values)); ctx.SystemItems[typeof(SearchResult).FullName] = searchResults; ctx.SetQueryResult(list.Select(x => (object)x).ToList()); }); return(step); }
public static void PopulateWithArguments <TSource>(this QueryParameterBuilder <TSource> queryParameterBuilder, ConnectionBuilder <ModelConventionType <TSource>, object> connectionBuilder) { queryParameterBuilder.ForEach(modelMember => { if (modelMember.SourceType == typeof(SearchModel) && modelMember.IsString) { connectionBuilder = modelMember.IsOptional ? connectionBuilder.Argument <ModelConventionInputType <SearchFilter> >(modelMember.Name, modelMember.Description) : connectionBuilder.Argument <NonNullGraphType <ModelConventionInputType <SearchFilter> > >(modelMember.Name, modelMember.Description); return; } if (modelMember.IsString) { connectionBuilder = modelMember.IsOptional ? connectionBuilder.Argument <ModelConventionInputType <StringFilter> >(modelMember.Name, modelMember.Description) : connectionBuilder.Argument <NonNullGraphType <ModelConventionInputType <StringFilter> > >(modelMember.Name, modelMember.Description); return; } if (modelMember.IsInt) { connectionBuilder = modelMember.IsOptional ? connectionBuilder.Argument <ModelConventionInputType <IntFilter> >(modelMember.Name, modelMember.Description) : connectionBuilder.Argument <NonNullGraphType <ModelConventionInputType <IntFilter> > >(modelMember.Name, modelMember.Description); return; } if (modelMember.IsDate) { connectionBuilder = modelMember.IsOptional ? connectionBuilder.Argument <ModelConventionInputType <DateFilter> >(modelMember.Name, modelMember.Description) : connectionBuilder.Argument <NonNullGraphType <ModelConventionInputType <DateFilter> > >(modelMember.Name, modelMember.Description); return; } if (modelMember.IsBool) { connectionBuilder = modelMember.IsOptional ? connectionBuilder.Argument <ModelConventionInputType <BoolFilter> >(modelMember.Name, modelMember.Description) : connectionBuilder.Argument <NonNullGraphType <ModelConventionInputType <BoolFilter> > >(modelMember.Name, modelMember.Description); return; } if (modelMember.IsGuid) { connectionBuilder = modelMember.IsOptional ? connectionBuilder.Argument <ModelConventionInputType <GuidFilter> >(modelMember.Name, modelMember.Description) : connectionBuilder.Argument <NonNullGraphType <ModelConventionInputType <GuidFilter> > >(modelMember.Name, modelMember.Description); return; } throw new NotImplementedException($"QueryArgument type is not yet implemented for {modelMember.Name}"); }); }
public static QueryArguments GetQueryArguments <TSource>(this QueryParameterBuilder <TSource> queryParameterBuilder) { var queryArguments = new List <QueryArgument>(); queryParameterBuilder.ForEach(modelMember => { if (modelMember.SourceType == typeof(SearchModel) && modelMember.IsString) { if (modelMember.IsOptional) { queryArguments.Add(new QueryArgument <ModelConventionInputType <SearchFilter> > { Name = modelMember.Name, Description = modelMember.Description }); } else { queryArguments.Add(new QueryArgument <NonNullGraphType <ModelConventionInputType <SearchFilter> > > { Name = modelMember.Name, Description = modelMember.Description }); } return; } if (modelMember.IsString) { if (modelMember.IsOptional) { queryArguments.Add(new QueryArgument <ModelConventionInputType <StringFilter> > { Name = modelMember.Name, Description = modelMember.Description }); } else { queryArguments.Add(new QueryArgument <NonNullGraphType <ModelConventionInputType <StringFilter> > > { Name = modelMember.Name, Description = modelMember.Description }); } return; } if (modelMember.IsInt) { if (modelMember.IsOptional) { queryArguments.Add(new QueryArgument <ModelConventionInputType <IntFilter> > { Name = modelMember.Name, Description = modelMember.Description }); } else { queryArguments.Add(new QueryArgument <NonNullGraphType <ModelConventionInputType <IntFilter> > > { Name = modelMember.Name, Description = modelMember.Description }); } return; } if (modelMember.IsDate) { if (modelMember.IsOptional) { queryArguments.Add(new QueryArgument <ModelConventionInputType <DateFilter> > { Name = modelMember.Name, Description = modelMember.Description }); } else { queryArguments.Add(new QueryArgument <NonNullGraphType <ModelConventionInputType <DateFilter> > > { Name = modelMember.Name, Description = modelMember.Description }); } return; } if (modelMember.IsBool) { if (modelMember.IsOptional) { queryArguments.Add(new QueryArgument <ModelConventionInputType <BoolFilter> > { Name = modelMember.Name, Description = modelMember.Description }); } else { queryArguments.Add(new QueryArgument <NonNullGraphType <ModelConventionInputType <BoolFilter> > > { Name = modelMember.Name, Description = modelMember.Description }); } return; } if (modelMember.IsGuid) { if (modelMember.IsOptional) { queryArguments.Add(new QueryArgument <ModelConventionInputType <GuidFilter> > { Name = modelMember.Name, Description = modelMember.Description }); } else { queryArguments.Add(new QueryArgument <NonNullGraphType <ModelConventionInputType <GuidFilter> > > { Name = modelMember.Name, Description = modelMember.Description }); } return; } throw new NotImplementedException($"QueryArgument type is not yet implemented for {modelMember.Name}"); }); return(new QueryArguments(queryArguments)); }
public QueryStepBuilder(QueryParameterBuilder <TSource> builder) { _builder = builder; }
/// <summary> /// Begin Search Builder. /// </summary> /// <typeparam name="TSource">Search source type.</typeparam> /// <param name="qb">QueryBuilder instance.</param> /// <returns>SearchQueryBuilder.</returns> public static SearchQueryBuilder <TSource> BeginSearch <TSource>( this QueryParameterBuilder <TSource> qb) { return(new SearchQueryBuilder <TSource>(Create(qb))); }