Skip to content

Commit

Permalink
Fixed issue with graphql generation not creating the correct method (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll authored Feb 3, 2024
1 parent a4f83ca commit e559e3e
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 20 deletions.
24 changes: 16 additions & 8 deletions src/Analyzers/GraphqlMutationActionBodyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ IParameterSymbol parameter
}

var sendRequestExpression = isStream
? streamMediatorRequest(IdentifierName(parameter.Name), cancellationTokenParameter)
: sendMediatorRequest(IdentifierName(parameter.Name), cancellationTokenParameter);
? streamMediatorRequest(IdentifierName(parameter.Name), IdentifierName(mediatorParameter.Name), cancellationTokenParameter)
: sendMediatorRequest(IdentifierName(parameter.Name), IdentifierName(mediatorParameter.Name), cancellationTokenParameter);

if (parameterType.IsRecord)
{
Expand All @@ -137,8 +137,8 @@ IParameterSymbol parameter
InitializerExpression(SyntaxKind.WithInitializerExpression, SeparatedList(expressions))
);
sendRequestExpression = isStream
? streamMediatorRequest(withExpression, cancellationTokenParameter)
: sendMediatorRequest(withExpression, cancellationTokenParameter);
? streamMediatorRequest(withExpression, IdentifierName(mediatorParameter.Name), cancellationTokenParameter)
: sendMediatorRequest(withExpression, IdentifierName(mediatorParameter.Name), cancellationTokenParameter);
}
}
else
Expand Down Expand Up @@ -185,7 +185,11 @@ IParameterSymbol parameter
.WithBody(block.NormalizeWhitespace())
.WithSemicolonToken(Token(SyntaxKind.None));

static ExpressionSyntax sendMediatorRequest(ExpressionSyntax nameSyntax, IParameterSymbol? cancellationTokenParameter)
static ExpressionSyntax sendMediatorRequest(
ExpressionSyntax nameSyntax,
ExpressionSyntax mediatorParameterSyntax,
IParameterSymbol? cancellationTokenParameter
)
{
var arguments = new List<ArgumentSyntax> { Argument(nameSyntax), };
if (cancellationTokenParameter is { })
Expand All @@ -200,7 +204,7 @@ static ExpressionSyntax sendMediatorRequest(ExpressionSyntax nameSyntax, IParame
InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("Mediator"),
mediatorParameterSyntax,
IdentifierName("Send")
)
)
Expand All @@ -222,7 +226,11 @@ static ExpressionSyntax sendMediatorRequest(ExpressionSyntax nameSyntax, IParame
);
}

static ExpressionSyntax streamMediatorRequest(ExpressionSyntax nameSyntax, IParameterSymbol? cancellationTokenParameter)
static ExpressionSyntax streamMediatorRequest(
ExpressionSyntax nameSyntax,
ExpressionSyntax mediatorParameterSyntax,
IParameterSymbol? cancellationTokenParameter
)
{
var arguments = new List<ArgumentSyntax> { Argument(nameSyntax), };
if (cancellationTokenParameter is { })
Expand All @@ -233,7 +241,7 @@ static ExpressionSyntax streamMediatorRequest(ExpressionSyntax nameSyntax, IPara
return InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("Mediator"),
mediatorParameterSyntax,
IdentifierName("CreateStream")
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class RocketMutation
/// <returns></returns>
public partial async Task<LaunchRecordModel> GetRocketLaunchRecord(IMediator mediator, GetRocketLaunchRecord.Request request)
{
var result = await Mediator.Send(request).ConfigureAwait(false);
var result = await mediator.Send(request).ConfigureAwait(false);
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class RocketMutation
/// <returns></returns>
public partial async Task<LaunchRecordModel> GetRocketLaunchRecord(IMediator mediator, GetRocketLaunchRecord.Request request)
{
var result = await Mediator.Send(request).ConfigureAwait(false);
var result = await mediator.Send(request).ConfigureAwait(false);
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class RocketMutation
/// <returns></returns>
public partial async Task<LaunchRecordModel> GetRocketLaunchRecord(IMediator mediator, GetRocketLaunchRecord.Request request)
{
var result = await Mediator.Send(request).ConfigureAwait(false);
var result = await mediator.Send(request).ConfigureAwait(false);
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class RocketMutation
/// <returns></returns>
public partial IAsyncEnumerable<LaunchRecordModel> GetRocketLaunchRecords([HotChocolate.ServiceAttribute] IMediator mediator, GetRocketLaunchRecords.Request request)
{
var result = Mediator.CreateStream(request);
var result = mediator.CreateStream(request);
return result;
}

Expand All @@ -23,7 +23,7 @@ public partial IAsyncEnumerable<LaunchRecordModel> GetRocketLaunchRecords([HotCh
/// <returns></returns>
public partial async Task<LaunchRecordModel> GetRocketLaunchRecord(IMediator mediator, GetRocketLaunchRecord.Request request)
{
var result = await Mediator.Send(request).ConfigureAwait(false);
var result = await mediator.Send(request).ConfigureAwait(false);
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public partial class RocketMutation
{
public partial async Task<RocketModel> GetRocket(IMediator mediator, GetRocket.Request request)
{
var result = await Mediator.Send(request).ConfigureAwait(false);
var result = await mediator.Send(request).ConfigureAwait(false);
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class RocketMutation
{
public partial async Task<RocketModel> Save2Rocket(IMediator mediator, Save2Rocket.Request request, ClaimsPrincipal cp, CancellationToken cancellationToken)
{
var result = await Mediator.Send(request with { ClaimsPrincipal = cp }, cancellationToken).ConfigureAwait(false);
var result = await mediator.Send(request with { ClaimsPrincipal = cp }, cancellationToken).ConfigureAwait(false);
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class RocketMutation
{
public partial async Task<RocketModel> Save2Rocket(IMediator mediator, Save2Rocket.Request request, CancellationToken cancellationToken)
{
var result = await Mediator.Send(request, cancellationToken).ConfigureAwait(false);
var result = await mediator.Send(request, cancellationToken).ConfigureAwait(false);
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class RocketMutation
{
public partial async Task<RocketModel> Save2Rocket(IMediator mediator, ClaimsPrincipal claimsPrincipal, Save2Rocket.Request request)
{
var result = await Mediator.Send(request with { ClaimsPrincipal = claimsPrincipal }).ConfigureAwait(false);
var result = await mediator.Send(request with { ClaimsPrincipal = claimsPrincipal }).ConfigureAwait(false);
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class RocketMutation
{
public partial async Task<RocketModel> Save2Rocket(IMediator mediator, Save2Rocket.Request request, CancellationToken token)
{
var result = await Mediator.Send(request, token).ConfigureAwait(false);
var result = await mediator.Send(request, token).ConfigureAwait(false);
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public partial class RocketMutation
public partial async Task<RocketModel> Save2Rocket(IMediator mediator, Save2Rocket.Request request, ClaimsPrincipal cp)
{
request.ClaimsPrincipal = cp;
var result = await Mediator.Send(request).ConfigureAwait(false);
var result = await mediator.Send(request).ConfigureAwait(false);
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class RocketMutation
{
public partial async Task<RocketModel> Save2Rocket(IMediator mediator, Save2Rocket.Request request)
{
var result = await Mediator.Send(request).ConfigureAwait(false);
var result = await mediator.Send(request).ConfigureAwait(false);
return result;
}
}
Expand Down

0 comments on commit e559e3e

Please sign in to comment.