Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 101 additions & 16 deletions examples/WireMock.Net.Console.NET8/MainApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,42 @@ enum Clients {
}
""";

private const string TestSchema =
private const string TestSchemaQueryStudents =
"""
type Query {
students:[Student]
}

type Student {
id:ID!
firstName:String
lastName:String
fullName:String
}
""";

private const string TestSchemaQueryStudentById =
"""
type Query {
studentById(id:ID!):Student
}

type Student {
id:ID!
firstName:String
lastName:String
fullName:String
}
""";

private const string TestSchemaQueryGreeting =
"""
type Query {
greeting:String
}
""";

private const string TestSchemaMutationMessage =
"""
scalar DateTime
scalar MyCustomScalar
Expand All @@ -153,19 +188,6 @@ type Mutation {
createAnotherMessage(x: MyCustomScalar, dt: DateTime): Message
updateMessage(id: ID!, input: MessageInput): Message
}

type Query {
greeting:String
students:[Student]
studentById(id:ID!):Student
}

type Student {
id:ID!
firstName:String
lastName:String
fullName:String
}
""";

private static void RunSse()
Expand Down Expand Up @@ -433,10 +455,73 @@ public static void Run()
.Given(Request.Create()
.WithPath("/graphql")
.UsingPost()
.WithBodyAsGraphQL(TestSchema, customScalars)
.WithGraphQLSchema(TestSchemaQueryStudents)
)
.RespondWith(Response.Create()
.WithBody("GraphQL is ok")
.WithHeader("Content-Type", "application/json")
.WithBody(
"""
{
"data": {
"students": [
{
"id": "1",
"firstName": "Alice",
"lastName": "Johnson",
"fullName": "Alice Johnson"
},
{
"id": "2",
"firstName": "Bob",
"lastName": "Smith",
"fullName": "Bob Smith"
}
]
}
}
""")
);

server
.Given(Request.Create()
.WithPath("/graphql")
.UsingPost()
.WithGraphQLSchema(TestSchemaQueryStudentById)
.WithBody(new JsonPartialWildcardMatcher("{ \"variables\": { \"sid\": \"1\" } }"))
)
.WithTitle("Student found")
.RespondWith(Response.Create()
.WithHeader("Content-Type", "application/json")
.WithBody(
"""
{
"data": {
"studentById": {
"id": "123",
"firstName": "John",
"lastName": "Doe",
"fullName": "John Doe"
}
}
}
""")
);

server
.Given(Request.Create()
.WithPath("/graphql")
.UsingPost()
.WithGraphQLSchema(TestSchemaQueryStudentById)
)
.WithTitle("Student not found")
.RespondWith(Response.Create()
.WithHeader("Content-Type", "application/json")
.WithBody(
"""
{
"data": null
}
""")
);
#endif

Expand Down
Loading