Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,28 @@ public static GraphQLEndpointConventionBuilder WithOptions(
this GraphQLEndpointConventionBuilder builder,
Action<GraphQLServerOptions> configure)
{
builder.Add(c => c.Metadata.Add(new GraphQLServerOptionsOverride(configure)));
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configure);

builder.Add(c =>
{
c.Metadata.Add(new GraphQLServerOptionsOverride(configure));

var options = new GraphQLServerOptions();

for (var i = c.Metadata.Count - 1; i >= 0; i--)
{
if (c.Metadata[i] is NitroAppOptions toolOptions)
{
options.Tool = toolOptions.Clone();
break;
}
}

configure(options);
c.Metadata.Add(options.Tool);
});

return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,37 @@ public async Task Fetch_Tool_When_Disabled(string version)
result.MatchSnapshot();
}

[Fact]
public async Task Fetch_Tool_When_Disabled_With_ServerOptions_Override()
{
// arrange
var server = CreateStarWarsServer(
configureConventions: e => e.WithOptions(o => o.Tool.Enable = false));

// act
var result = await GetAsync(server, "/graphql/index.html");

// assert
result.MatchSnapshot();
}

[Fact]
public async Task Fetch_Tool_Config_With_ServerOptions_Override_Using_Global_Tool_Options()
{
// arrange
var server = CreateStarWarsServer(
configureServices: s => s
.AddGraphQL()
.ModifyServerOptions(o => o.Tool.Title = "Global"),
configureConventions: e => e.WithOptions(o => o.Tool.Title += " Local"));

// act
var result = await GetNitroConfigAsync(server);

// assert
result.MatchSnapshot();
}

[Fact]
public async Task Fetch_Tool_Config_With_Options()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Content": "{\"title\":\"Global Local\",\"useBrowserUrlAsEndpoint\":true,\"useGet\":false}",
"ContentType": {
"CharSet": "utf-8",
"Parameters": [
{
"Name": "charset",
"Value": "utf-8"
}
],
"MediaType": "application/json"
},
"StatusCode": "OK"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Content": "",
"ContentType": null,
"StatusCode": "NotFound"
}
Loading