Я использую .Net core 2.2 (Visual Studio 2017) и Package (nuget) GraphiQL (1.2.0) и GraphQL (3.0.0-preview-1175), для Dapper это пакет: Dapper (2.0.3.0)) Я использую Dapper для процедуры в c #.
public async Task<IEnumerable<object>> GetAll(string startDate, string endDate, string ruleId)
{
try
{
string connection = _configuration.GetConnectionString("XtractorReport");
using (SqlConnection conn = new SqlConnection(connection))
{
conn.Open();
_ExtractionsCache = await conn.QueryAsync("dbo.[GET_EXTRACTION_DETAIL_REPORT]", new { INITDATETIME = startDate, ENDDATETIME = endDate, RULEID = ruleId }, commandType: System.Data.CommandType.StoredProcedure);
return _ExtractionsCache;
}
}
catch (Exception ex)
{
return null;
}
}
Мой запрос в GraphQL:
public BlogQuery(IExtractionRepository repos)
{
try
{
Field<ListGraphType<ExtractionType>>("report",
arguments: new QueryArguments(new QueryArgument[]
{
new QueryArgument<StringGraphType>{Name="startDate"},
new QueryArgument<StringGraphType>{Name="endDate"},
new QueryArgument<StringGraphType>{Name="ruleId"},
}),
resolve: ctx =>
{
string startDate = ctx.GetArgument<string>("startDate");
string endDate = ctx.GetArgument<string>("endDate");
string ruleId = ctx.GetArgument<string>("ruleId");
//TODO: usar aplicacao para obter dados
return repos.GetAll(startDate, endDate, ruleId);
});
}
catch (System.Exception ex)
{
throw ex;
}
}
}
Мой EndPoint это выглядит так:
[HttpPost]
public async Task<IActionResult> Post([FromBody]GraphQLQuery query)
{
// Recebendo valores da pesquisa
var inputs = query.Variables.ToInputs();
// passando o contexto para os Schemas do GraphQL
var schema = _schema;
// passando os parâmetros da nossa pesquisa
var result = await new DocumentExecuter().ExecuteAsync(_ =>
{
_.Schema = schema;
_.Query = query.Query;
_.OperationName = query.OperationName;
_.Inputs = inputs;
}).ConfigureAwait(false);
if (result.Errors?.Count > 0)
{
return BadRequest(result);
}
return Ok(result);
}
Мой тип в GraphQL:
public class ExtractionType : ObjectGraphType<Extraction>
{
public ExtractionType()
{
Name = "report";
Field(x => x.Id, type: typeof(IdGraphType)).Description("SysId extração");
Field(x => x.Name, type: typeof(StringGraphType)).Description("Name extração");
Field(x => x.SEQ_ID, type: typeof(StringGraphType)).Description("SEQ_ID extração");
Field(x => x.StartTime, type: typeof(DateTimeGraphType)).Description("Começo extração");
Field(x => x.EndTime, type: typeof(DateTimeGraphType)).Description("Fim extração");
Field(x => x.Duration, type: typeof(IntGraphType)).Description("Duration extração");
}
}
Процедура в SQL SERVER:
SELECT
r."Name" as "Name"
,c.SYSID as Id
,RoW_nUmBEr() OVER (PARTITION BY c.SYSID ORDER BY c.DateRef) as "SEQ_ID"
,c.[DATEREF] StartTime
,[FINISHED] EndTime
,datediff(SECOND,c.dateref,c.finished) Duration
FROM [XtractorReportDB].[dbo].[RetrievalHistory] c (nolock)
join XtractorReportDB.dbo.RulesRetrievalDetail (nolock) rrd on c.SYSID = rrd.RETRIEVALSYSID
join XtractorRecordsStagingDB.dbo.Rules (nolock) r on rrd.RuleId = r.Id
where
purpose = 'RETRIEVAL' and c.DATEREF between '2019-07-07' and '2019-07-08'
order by
c.PARTITIONID,
c.SYSID,
RoW_nUmBEr() OVER (PARTITION BY c.SYSID ORDER BY c.DateRef)
desc
Ошибка GraphQL PlayGround:
введите описание изображенияздесь
Исключительная ошибка: введите описание изображения здесь