1
+ // Copyright © WireMock.Net
2
+
3
+ using System ;
4
+ using System . Collections . Generic ;
5
+ using GraphQL . Types ;
6
+ using Stef . Validation ;
7
+ using WireMock . Matchers ;
8
+ using WireMock . Matchers . Request ;
9
+ using WireMock . Models ;
10
+ using WireMock . Models . GraphQL ;
11
+
12
+ namespace WireMock . RequestBuilders ;
13
+
14
+ /// <summary>
15
+ /// IRequestBuilderExtensions extensions for GraphQL.
16
+ /// </summary>
17
+ // ReSharper disable once InconsistentNaming
18
+ public static class IRequestBuilderExtensions
19
+ {
20
+ /// <summary>
21
+ /// WithBodyAsGraphQL: The GraphQL body as a string.
22
+ /// </summary>
23
+ /// <param name="requestBuilder">The <see cref="IRequestBuilder"/>.</param>
24
+ /// <param name="schema">The GraphQL schema.</param>
25
+ /// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
26
+ /// <returns>The <see cref="IRequestBuilder"/>.</returns>
27
+ public static IRequestBuilder WithGraphQLSchema ( this IRequestBuilder requestBuilder , string schema , MatchBehaviour matchBehaviour = MatchBehaviour . AcceptOnMatch )
28
+ {
29
+ return Guard . NotNull ( requestBuilder ) . Add ( new RequestMessageGraphQLMatcher ( matchBehaviour , schema ) ) ;
30
+ }
31
+
32
+ /// <summary>
33
+ /// WithBodyAsGraphQL: The GraphQL schema as a string.
34
+ /// </summary>
35
+ /// <param name="requestBuilder">The <see cref="IRequestBuilder"/>.</param>
36
+ /// <param name="schema">The GraphQL schema.</param>
37
+ /// <param name="customScalars">A dictionary defining the custom scalars used in this schema. (optional)</param>
38
+ /// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
39
+ /// <returns>The <see cref="IRequestBuilder"/>.</returns>
40
+ public static IRequestBuilder WithGraphQLSchema ( this IRequestBuilder requestBuilder , string schema , IDictionary < string , Type > ? customScalars , MatchBehaviour matchBehaviour = MatchBehaviour . AcceptOnMatch )
41
+ {
42
+ return Guard . NotNull ( requestBuilder ) . Add ( new RequestMessageGraphQLMatcher ( matchBehaviour , schema , customScalars ) ) ;
43
+ }
44
+
45
+ /// <summary>
46
+ /// WithBodyAsGraphQL: The GraphQL schema as a <see cref="ISchema"/>.
47
+ /// </summary>
48
+ /// <param name="requestBuilder">The <see cref="IRequestBuilder"/>.</param>
49
+ /// <param name="schema">The GraphQL schema.</param>
50
+ /// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
51
+ /// <returns>The <see cref="IRequestBuilder"/>.</returns>
52
+ public static IRequestBuilder WithGraphQLSchema ( this IRequestBuilder requestBuilder , ISchema schema , MatchBehaviour matchBehaviour = MatchBehaviour . AcceptOnMatch )
53
+ {
54
+ return Guard . NotNull ( requestBuilder ) . Add ( new RequestMessageGraphQLMatcher ( matchBehaviour , new SchemaDataWrapper ( schema ) ) ) ;
55
+ }
56
+
57
+ /// <summary>
58
+ /// WithBodyAsGraphQL: The GraphQL schema as a <see cref="ISchema"/>.
59
+ /// </summary>
60
+ /// <param name="requestBuilder">The <see cref="IRequestBuilder"/>.</param>
61
+ /// <param name="schema">The GraphQL schema.</param>
62
+ /// <param name="customScalars">A dictionary defining the custom scalars used in this schema. (optional)</param>
63
+ /// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
64
+ /// <returns>The <see cref="IRequestBuilder"/>.</returns>
65
+ public static IRequestBuilder WithGraphQLSchema ( this IRequestBuilder requestBuilder , ISchema schema , IDictionary < string , Type > ? customScalars , MatchBehaviour matchBehaviour = MatchBehaviour . AcceptOnMatch )
66
+ {
67
+ return Guard . NotNull ( requestBuilder ) . Add ( new RequestMessageGraphQLMatcher ( matchBehaviour , new SchemaDataWrapper ( schema ) , customScalars ) ) ;
68
+ }
69
+
70
+ /// <summary>
71
+ /// WithBodyAsGraphQL: The GraphQL schema as a <see cref="ISchemaData"/>.
72
+ /// </summary>
73
+ /// <param name="requestBuilder">The <see cref="IRequestBuilder"/>.</param>
74
+ /// <param name="schema">The GraphQL schema.</param>
75
+ /// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
76
+ /// <returns>The <see cref="IRequestBuilder"/>.</returns>
77
+ public static IRequestBuilder WithGraphQLSchema ( this IRequestBuilder requestBuilder , ISchemaData schema , MatchBehaviour matchBehaviour = MatchBehaviour . AcceptOnMatch )
78
+ {
79
+ return Guard . NotNull ( requestBuilder ) . Add ( new RequestMessageGraphQLMatcher ( matchBehaviour , schema ) ) ;
80
+ }
81
+
82
+ /// <summary>
83
+ /// WithBodyAsGraphQL: The GraphQL schema as a <see cref="ISchemaData"/>.
84
+ /// </summary>
85
+ /// <param name="requestBuilder">The <see cref="IRequestBuilder"/>.</param>
86
+ /// <param name="schema">The GraphQL schema.</param>
87
+ /// <param name="customScalars">A dictionary defining the custom scalars used in this schema. (optional)</param>
88
+ /// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
89
+ /// <returns>The <see cref="IRequestBuilder"/>.</returns>
90
+ public static IRequestBuilder WithGraphQLSchema ( this IRequestBuilder requestBuilder , ISchemaData schema , IDictionary < string , Type > ? customScalars , MatchBehaviour matchBehaviour = MatchBehaviour . AcceptOnMatch )
91
+ {
92
+ return Guard . NotNull ( requestBuilder ) . Add ( new RequestMessageGraphQLMatcher ( matchBehaviour , schema , customScalars ) ) ;
93
+ }
94
+ }
0 commit comments