-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Azure Functions support #966
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
01f08fb
Add Azure Functions support
Shane32 319583a
Update api approvals
Shane32 6547483
Update controller sample
Shane32 0f3fbc9
Update
Shane32 790fef8
Update api approvals
Shane32 a02c3c0
Update
Shane32 fd4f4ec
Update
Shane32 df7c78f
Update src/Ui.GraphiQL/GraphiQLActionResult.cs
Shane32 52c8d37
Update src/Ui.Playground/PlaygroundActionResult.cs
Shane32 f510a52
Update src/Ui.Playground/PlaygroundActionResult.cs
Shane32 81bd537
Update src/Ui.GraphiQL/GraphiQLActionResult.cs
Shane32 7eeba0c
Update
Shane32 6935c78
Update samples/Samples.AzureFunctions/GraphQL.cs
Shane32 4b71971
Move IDE0060 disable to csproj
Shane32 a40e0e7
Merge branch 'azure_functions' of https://github.com/graphql-dotnet/s…
Shane32 bb0de55
Add Altair and Voyager action results
Shane32 029a059
Update readme
Shane32 483ba72
Add test project for Azure Functions
Shane32 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using GraphQL.Server.Transports.AspNetCore.AzureFunctions; | ||
using GraphQL.Server.Ui.Playground; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.Http; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Samples.AzureFunctions; | ||
|
||
public class GraphQL | ||
{ | ||
[FunctionName("GraphQL")] | ||
public static IActionResult RunGraphQL( | ||
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest request, | ||
ILogger log) | ||
{ | ||
log.LogInformation("C# HTTP trigger function processed a GraphQL request."); | ||
|
||
return new AzureGraphQLActionResult(request); | ||
} | ||
|
||
[FunctionName("Playground")] | ||
public static IActionResult RunPlayground( | ||
[HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest request, | ||
ILogger log) | ||
{ | ||
log.LogInformation("C# HTTP trigger function processed a request for the GraphQL Playground UI."); | ||
|
||
return new PlaygroundActionResult(opts => opts.GraphQLEndPoint = "/api/graphql"); // /api/graphql route will call RunGraphQL method | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
samples/Samples.AzureFunctions/Properties/serviceDependencies.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"dependencies": { | ||
"appInsights1": { | ||
"type": "appInsights" | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
samples/Samples.AzureFunctions/Properties/serviceDependencies.local.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"dependencies": { | ||
"appInsights1": { | ||
"type": "appInsights.sdk" | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
samples/Samples.AzureFunctions/Samples.AzureFunctions.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<AzureFunctionsVersion>v4</AzureFunctionsVersion> | ||
<NoWarn>$(NoWarn);IDE0060</NoWarn> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Transports.AspNetCore\Transports.AspNetCore.csproj" /> | ||
<ProjectReference Include="..\..\src\Ui.GraphiQL\Ui.GraphiQL.csproj" /> | ||
<ProjectReference Include="..\..\src\Ui.Playground\Ui.Playground.csproj" /> | ||
<ProjectReference Include="..\Samples.Schemas.Chat\Samples.Schemas.Chat.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Update="host.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using GraphQL; | ||
using Microsoft.Azure.Functions.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Chat = GraphQL.Samples.Schemas.Chat; | ||
|
||
[assembly: FunctionsStartup(typeof(Samples.AzureFunctions.Startup))] | ||
namespace Samples.AzureFunctions; | ||
|
||
public class Startup : FunctionsStartup | ||
{ | ||
public override void Configure(IFunctionsHostBuilder builder) | ||
{ | ||
builder.Services.AddSingleton<Chat.IChat, Chat.Chat>(); | ||
|
||
builder.Services.AddGraphQL(b => b | ||
.AddAutoSchema<Chat.Query>(s => s | ||
.WithMutation<Chat.Mutation>() | ||
.WithSubscription<Chat.Subscription>()) | ||
.AddSystemTextJson() | ||
.AddAzureFunctionsMiddleware()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version": "2.0", | ||
"logging": { | ||
"applicationInsights": { | ||
"samplingSettings": { | ||
"isEnabled": true, | ||
"excludedTypes": "Request" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspected that the schema should be created every time so your note about overhead here
will not affect the overall costs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking the same thing. I think we will find that the alternative approach for Azure Functions is better overall.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible that if multiple calls are made in succession maybe then the schema would not need to be reinitialized.
But regardless, I looked at GraphQLHttpMiddleware and it seems that we can make some private readonly fields static anyway. At which point, initializing one class should have little effect on speed/memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will have any effect only if Azure Function environment does not unload entirely the whole app (dll/domain/process/whatever) from memory.