Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Feb 26, 2024
1 parent 3cfd489 commit 398ea09
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'">
<DefineConstants>$(DefineConstants);GRAPHQL;MIMEKIT;PROTOBUF</DefineConstants>
<DefineConstants>$(DefineConstants);MIMEKIT;PROTOBUF</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,8 @@ private IReadOnlyList<MatchResult> CalculateMatchResults(IRequestMessage request
return Matchers == null ? new[] { new MatchResult() } : Matchers.Select(matcher => CalculateMatchResult(requestMessage, matcher)).ToArray();
}

//#if GRAPHQL
private static IMatcher[] CreateMatcherArray(MatchBehaviour matchBehaviour, AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern, object?> schema, IDictionary<string, Type>? customScalars)
{
return new[] { TypeLoader.Load<IGraphQLMatcher>(schema, customScalars, matchBehaviour, MatchOperator.Or) }.Cast<IMatcher>().ToArray();
}
//#else
// private static IMatcher[] CreateMatcherArray(MatchBehaviour matchBehaviour, object schema, IDictionary<string, Type>? customScalars)
// {
// throw new System.NotSupportedException("The GrapQLMatcher can not be used for .NETStandard1.3 or .NET Framework 4.6.1 or lower.");
// }
//#endif
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ReSharper disable InconsistentNaming
using System;
using System.Collections.Generic;
using Stef.Validation;
using WireMock.Matchers;
using WireMock.Matchers.Request;

Expand All @@ -14,6 +15,7 @@ public static class IRequestBuilderExtensions
/// <summary>
/// WithGraphQLSchema: The GraphQL schema as a string.
/// </summary>
/// <param name="requestBuilder">The <see cref="IRequestBuilder"/>.</param>
/// <param name="schema">The GraphQL schema.</param>
/// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
Expand All @@ -25,6 +27,7 @@ public static IRequestBuilder WithGraphQLSchema(this IRequestBuilder requestBuil
/// <summary>
/// WithGraphQLSchema: The GraphQL schema as a string.
/// </summary>
/// <param name="requestBuilder">The <see cref="IRequestBuilder"/>.</param>
/// <param name="schema">The GraphQL schema.</param>
/// <param name="customScalars">A dictionary defining the custom scalars used in this schema. (optional)</param>
/// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
Expand All @@ -37,29 +40,32 @@ public static IRequestBuilder WithGraphQLSchema(this IRequestBuilder requestBuil
/// <summary>
/// WithBodyAsGraphQL: The GraphQL schema as a string.
/// </summary>
/// <param name="requestBuilder">The <see cref="IRequestBuilder"/>.</param>
/// <param name="schema">The GraphQL schema.</param>
/// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public static IRequestBuilder WithBodyAsGraphQL(this IRequestBuilder requestBuilder, string schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
return requestBuilder.Add(new RequestMessageGraphQLMatcher(matchBehaviour, schema));
return Guard.NotNull(requestBuilder).Add(new RequestMessageGraphQLMatcher(matchBehaviour, schema));
}

/// <summary>
/// WithBodyAsGraphQL: The GraphQL schema as a string.
/// </summary>
/// <param name="requestBuilder">The <see cref="IRequestBuilder"/>.</param>
/// <param name="schema">The GraphQL schema.</param>
/// <param name="customScalars">A dictionary defining the custom scalars used in this schema. (optional)</param>
/// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public static IRequestBuilder WithBodyAsGraphQL(this IRequestBuilder requestBuilder, string schema, IDictionary<string, Type>? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
return requestBuilder.Add(new RequestMessageGraphQLMatcher(matchBehaviour, schema, customScalars));
return Guard.NotNull(requestBuilder).Add(new RequestMessageGraphQLMatcher(matchBehaviour, schema, customScalars));
}

/// <summary>
/// WithGraphQLSchema: The GraphQL schema as a ISchema.
/// </summary>
/// <param name="requestBuilder">The <see cref="IRequestBuilder"/>.</param>
/// <param name="schema">The GraphQL schema.</param>
/// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
Expand All @@ -71,6 +77,7 @@ public static IRequestBuilder WithGraphQLSchema(this IRequestBuilder requestBuil
/// <summary>
/// WithGraphQLSchema: The GraphQL schema as a ISchema.
/// </summary>
/// <param name="requestBuilder">The <see cref="IRequestBuilder"/>.</param>
/// <param name="schema">The GraphQL schema.</param>
/// <param name="customScalars">A dictionary defining the custom scalars used in this schema. (optional)</param>
/// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
Expand All @@ -83,6 +90,7 @@ public static IRequestBuilder WithGraphQLSchema(this IRequestBuilder requestBuil
/// <summary>
/// WithBodyAsGraphQL: The GraphQL schema as a ISchema.
/// </summary>
/// <param name="requestBuilder">The <see cref="IRequestBuilder"/>.</param>
/// <param name="schema">The GraphQL schema.</param>
/// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
Expand All @@ -94,18 +102,20 @@ public static IRequestBuilder WithBodyAsGraphQL(this IRequestBuilder requestBuil
/// <summary>
/// WithBodyAsGraphQL: The GraphQL schema as a ISchema.
/// </summary>
/// <param name="requestBuilder">The <see cref="IRequestBuilder"/>.</param>
/// <param name="schema">The GraphQL schema.</param>
/// <param name="customScalars">A dictionary defining the custom scalars used in this schema. (optional)</param>
/// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public static IRequestBuilder WithBodyAsGraphQL(this IRequestBuilder requestBuilder, GraphQL.Types.ISchema schema, IDictionary<string, Type>? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
return requestBuilder.Add(new RequestMessageGraphQLMatcher(matchBehaviour, schema, customScalars));
return Guard.NotNull(requestBuilder).Add(new RequestMessageGraphQLMatcher(matchBehaviour, schema, customScalars));
}

/// <summary>
/// WithBodyAsGraphQLSchema: Body as GraphQL schema as a string.
/// </summary>
/// <param name="requestBuilder">The <see cref="IRequestBuilder"/>.</param>
/// <param name="body">The GraphQL schema.</param>
/// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
Expand Down
4 changes: 0 additions & 4 deletions src/WireMock.Net.GraphQL/WireMock.Net.GraphQL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<!--<PropertyGroup>
<DefineConstants>$(DefineConstants);GRAPHQL</DefineConstants>
</PropertyGroup>-->

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
Expand Down
3 changes: 1 addition & 2 deletions src/WireMock.Net/Serialization/MatcherMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,10 @@ public MatcherMapper(WireMockServerSettings settings)
case XPathMatcher xpathMatcher:
model.XmlNamespaceMap = xpathMatcher.XmlNamespaceMap;
break;
#if GRAPHQL

case IGraphQLMatcher graphQLMatcher:
model.CustomScalars = graphQLMatcher.CustomScalars;
break;
#endif
}

switch (matcher)
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/WireMock.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard1.3' and '$(TargetFramework)' != 'net451' and '$(TargetFramework)' != 'net452' and '$(TargetFramework)' != 'net46' and '$(TargetFramework)' != 'net461'">
<DefineConstants>$(DefineConstants);GRAPHQL;MIMEKIT;PROTOBUF</DefineConstants>
<DefineConstants>$(DefineConstants);MIMEKIT;PROTOBUF</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard1.3' and '$(TargetFramework)' != 'net451' and '$(TargetFramework)' != 'net452' and '$(TargetFramework)' != 'net46' ">
Expand Down

0 comments on commit 398ea09

Please sign in to comment.