diff --git a/examples/WireMock.Net.Console.NET8/MainApp.cs b/examples/WireMock.Net.Console.NET8/MainApp.cs index 7f8ac8f3a..942177dc8 100644 --- a/examples/WireMock.Net.Console.NET8/MainApp.cs +++ b/examples/WireMock.Net.Console.NET8/MainApp.cs @@ -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 @@ -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() @@ -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