Skip to content

Commit 7a187df

Browse files
authored
Add more examples for WithGraphQLSchema (#1335)
1 parent e6ff877 commit 7a187df

File tree

1 file changed

+101
-16
lines changed

1 file changed

+101
-16
lines changed

examples/WireMock.Net.Console.NET8/MainApp.cs

Lines changed: 101 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,42 @@ enum Clients {
132132
}
133133
""";
134134

135-
private const string TestSchema =
135+
private const string TestSchemaQueryStudents =
136+
"""
137+
type Query {
138+
students:[Student]
139+
}
140+
141+
type Student {
142+
id:ID!
143+
firstName:String
144+
lastName:String
145+
fullName:String
146+
}
147+
""";
148+
149+
private const string TestSchemaQueryStudentById =
150+
"""
151+
type Query {
152+
studentById(id:ID!):Student
153+
}
154+
155+
type Student {
156+
id:ID!
157+
firstName:String
158+
lastName:String
159+
fullName:String
160+
}
161+
""";
162+
163+
private const string TestSchemaQueryGreeting =
164+
"""
165+
type Query {
166+
greeting:String
167+
}
168+
""";
169+
170+
private const string TestSchemaMutationMessage =
136171
"""
137172
scalar DateTime
138173
scalar MyCustomScalar
@@ -153,19 +188,6 @@ type Mutation {
153188
createAnotherMessage(x: MyCustomScalar, dt: DateTime): Message
154189
updateMessage(id: ID!, input: MessageInput): Message
155190
}
156-
157-
type Query {
158-
greeting:String
159-
students:[Student]
160-
studentById(id:ID!):Student
161-
}
162-
163-
type Student {
164-
id:ID!
165-
firstName:String
166-
lastName:String
167-
fullName:String
168-
}
169191
""";
170192

171193
private static void RunSse()
@@ -433,10 +455,73 @@ public static void Run()
433455
.Given(Request.Create()
434456
.WithPath("/graphql")
435457
.UsingPost()
436-
.WithBodyAsGraphQL(TestSchema, customScalars)
458+
.WithGraphQLSchema(TestSchemaQueryStudents)
437459
)
438460
.RespondWith(Response.Create()
439-
.WithBody("GraphQL is ok")
461+
.WithHeader("Content-Type", "application/json")
462+
.WithBody(
463+
"""
464+
{
465+
"data": {
466+
"students": [
467+
{
468+
"id": "1",
469+
"firstName": "Alice",
470+
"lastName": "Johnson",
471+
"fullName": "Alice Johnson"
472+
},
473+
{
474+
"id": "2",
475+
"firstName": "Bob",
476+
"lastName": "Smith",
477+
"fullName": "Bob Smith"
478+
}
479+
]
480+
}
481+
}
482+
""")
483+
);
484+
485+
server
486+
.Given(Request.Create()
487+
.WithPath("/graphql")
488+
.UsingPost()
489+
.WithGraphQLSchema(TestSchemaQueryStudentById)
490+
.WithBody(new JsonPartialWildcardMatcher("{ \"variables\": { \"sid\": \"1\" } }"))
491+
)
492+
.WithTitle("Student found")
493+
.RespondWith(Response.Create()
494+
.WithHeader("Content-Type", "application/json")
495+
.WithBody(
496+
"""
497+
{
498+
"data": {
499+
"studentById": {
500+
"id": "123",
501+
"firstName": "John",
502+
"lastName": "Doe",
503+
"fullName": "John Doe"
504+
}
505+
}
506+
}
507+
""")
508+
);
509+
510+
server
511+
.Given(Request.Create()
512+
.WithPath("/graphql")
513+
.UsingPost()
514+
.WithGraphQLSchema(TestSchemaQueryStudentById)
515+
)
516+
.WithTitle("Student not found")
517+
.RespondWith(Response.Create()
518+
.WithHeader("Content-Type", "application/json")
519+
.WithBody(
520+
"""
521+
{
522+
"data": null
523+
}
524+
""")
440525
);
441526
#endif
442527

0 commit comments

Comments
 (0)