Skip to content

Commit cdc41b0

Browse files
committed
Updates to Readme! And Options naming improvements.
1 parent cf63ae3 commit cdc41b0

File tree

6 files changed

+73
-13
lines changed

6 files changed

+73
-13
lines changed

GraphQL.AzureFunctionsProxy.Tests/AzureFunctions/HelloWorldFunctionsStartup.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public override void Configure(IFunctionsHostBuilder builder)
3333
//TODO: Test multiple SchemaNames...
3434
services.AddAzureFunctionsGraphQL((options) =>
3535
{
36-
options.AzureFunctionsGraphQLRoutePath = "/api/graphql";
36+
options.AzureFunctionsRoutePath = "/api/graphql";
3737
});
3838
}
3939
}

GraphQL.AzureFunctionsProxy/GraphQL.AzureFunctionsProxy.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<RepositoryUrl>https://github.com/cajuncoding/HotChocolate.AzureFunctionsProxy</RepositoryUrl>
1212
<PackageTags>graphql, graph-ql, hotchocolate, azure, functions, serverless</PackageTags>
1313
<PackageReleaseNotes>- Added support for download of the Schema (?SDL)
14-
- Added support for functioning Playground (when configured correctly iin the AzureFunction HttpTrigger)
14+
- Added support for functioning Playground (when configured correctly in the Azure Function HttpTrigger &amp; Route Binding)
1515
- Maintained current version compatibility with HC v11.0.4
1616

1717
Prior Releases Notes:

GraphQL.AzureFunctionsProxy/GraphQLAzureFunctionsConfigOptions.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ namespace HotChocolate.AzureFunctionsProxy
66
{
77
public class GraphQLAzureFunctionsConfigOptions
88
{
9-
public string AzureFunctionsGraphQLRoutePath { get; set; } = "/api/graphql";
10-
public bool EnableSchemaDefinitionMiddleware { get; set; } = true;
11-
public bool EnablePlayground { get; set; } = true;
12-
public bool EnableGetRequestMiddleware { get; set; } = true;
9+
public string AzureFunctionsRoutePath { get; set; } = "/api/graphql";
10+
public bool EnableSchemaDefinitionDownload { get; set; } = true;
11+
public bool EnablePlaygroundWebApp { get; set; } = true;
12+
public bool EnableGETRequests { get; set; } = true;
1313
}
1414
}

GraphQL.AzureFunctionsProxy/GraphQLAzureFunctionsMiddlewareProxy.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public GraphQLAzureFunctionsMiddlewareProxy(
6363
this.FileProvider = GraphQLInitHelpers.CreateEmbeddedFileProvider();
6464

6565
//Set the RoutePath; a dependency of all dynamic file serving Middleware!
66-
this.RoutePath = new PathString(Options.AzureFunctionsGraphQLRoutePath);
66+
this.RoutePath = new PathString(Options.AzureFunctionsRoutePath);
6767

6868
//Initialize the Primary Middleware (POST) as needed for references to GetExecutorAsync() for Error Handling, etc....
6969
//NOTE: This will also return the Middleware to be used as the primary reference.
@@ -97,7 +97,7 @@ private MiddlewareBase ConfigureMiddlewareChainOfResponsibility()
9797
// - ToolStaticFileMiddleware
9898
// - HttpGetMiddleware
9999

100-
if (Options.EnableGetRequestMiddleware)
100+
if (Options.EnableGETRequests)
101101
{
102102
var httpGetMiddlewareShim = new HttpGetMiddleware(
103103
this.MiddlewareProxyDelegate,
@@ -109,7 +109,7 @@ private MiddlewareBase ConfigureMiddlewareChainOfResponsibility()
109109
this.MiddlewareProxyDelegate = (httpContext) => httpGetMiddlewareShim.InvokeAsync(httpContext);
110110
}
111111

112-
if (Options.EnablePlayground)
112+
if (Options.EnablePlaygroundWebApp)
113113
{
114114
var toolStaticFileMiddlewareShim = new ToolStaticFileMiddleware(
115115
this.MiddlewareProxyDelegate,
@@ -135,7 +135,7 @@ private MiddlewareBase ConfigureMiddlewareChainOfResponsibility()
135135
this.MiddlewareProxyDelegate = (httpContext) => toolDefaultFileMiddlewareShim.Invoke(httpContext);
136136
}
137137

138-
if (Options.EnableSchemaDefinitionMiddleware)
138+
if (Options.EnableSchemaDefinitionDownload)
139139
{
140140
var httpGetSchemaMiddlewareShim = new HttpGetSchemaMiddleware(
141141
this.MiddlewareProxyDelegate,

PureCodeFirst-AzureFunctions-v11/Startup.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override void Configure(IFunctionsHostBuilder builder)
5858
//The Path must match the exact routing path that the Azure Function HttpTrigger is bound to.
5959
//NOTE: ThIs includes the /api/ prefix unless it was specifically removed or changed in the host.json file.
6060
//NOTE: THe default value is `/api/graphql`, but it's being done here to illustrate how to set the value.
61-
options.AzureFunctionsGraphQLRoutePath = "/api/graphql";
61+
options.AzureFunctionsRoutePath = "/api/graphql";
6262
});
6363
}
6464
}

README.md

+62-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
## An (Unofficial) Extension pack for using HotChocolate GraphQL framework within Azure Functions for v11.
33

44
**Update Notes:**
5+
- Added support for ?SDL download of the Schema (?SDL)
6+
- Added support for Functioning Playground (when configured correctly iin the AzureFunction HttpTrigger route binding & new path option).
7+
- Reduced the number of awaits used in the Middleware proxy for performance.
8+
- Maintained compatibility with v11.0.4.
9+
10+
Prior Release Notes:
511
- Added ConfigureAwait(false) to all awaits for performance.
612
- Bumped to HC v11.0.4
713
- Updated to HC v11.0.1.1 due to critical fixes in HC v11.0.1 that resolve an issue in HC core that had broken Interfaces (which impacted the accompanying Star Wars Demo)
@@ -70,12 +76,24 @@ handle the request.
7076

7177
### Startup Configuration
7278
1. The following Middleware initializer must be added into a valid AzureFunctions Configuration 'Startup.cs'
73-
* All other elements of HotChocolate initialization are the same using the v11 API.
79+
- All other elements of HotChocolate initialization are the same using the v11 API.
7480
```csharp
7581
//Finally Initialize AzureFunctions Executor Proxy here...
7682
services.AddAzureFunctionsGraphQL();
7783
```
7884

85+
- Or to enable/disable new features for Schema Download (?SDL) or Playground (DEFAULT is enabled):
86+
```csharp
87+
//Finally Initialize AzureFunctions Executor Proxy here...
88+
services.AddAzureFunctionsGraphQL((options) =>
89+
{
90+
options.AzureFunctionsRoutePath = "/api/graphql"; //Default value is already `/api/graphql`
91+
options.EnableSchemaDefinitionDownload = true; //Default is already Enabled (true)
92+
options.EnablePlaygroundWebApp = true; //Default is already Enabled (true)
93+
options.EnableGETRequests = true; //Default is already Enabled (true)
94+
});
95+
```
96+
7997
* Note: The namespace for this new middleware and proxy classes as needed is:
8098
```csharp
8199
using HotChocolate.AzureFunctionsProxy
@@ -100,7 +118,8 @@ public class StarWarsFunctionEndpoint
100118
```csharp
101119
[FunctionName(nameof(StarWarsFunctionEndpoint))]
102120
public async Task<IActionResult> Run(
103-
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "graphql")] HttpRequest req,
121+
//NOTE: The Route must be configured to match wildcard path for the Playground to function properly.
122+
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "graphql/{*path}")] HttpRequest req,
104123
ILogger logger,
105124
CancellationToken cancellationToken
106125
)
@@ -115,7 +134,48 @@ public class StarWarsFunctionEndpoint
115134
}
116135
```
117136

137+
### Enabling the Playground from AzureFunctions
138+
1. To enable the Playground the Azure Function must be configured properly to serve all Web Assets dynamically
139+
for various paths, and the Middleware must be told what the AzureFunction path is via the Options configuration.
140+
141+
- To do this, the HttpTrigger must be configured with wildcard matching on the path so that the Function will be bound
142+
to all paths for processing (e.g. CSS, JavaScript, Manifest.json asset requests):
143+
144+
- Take note of the ***/{\*path}*** component of the Route binding!
145+
```csharp
146+
//NOTE: The Route must be configured to match wildcard path for the Playground to function properly.
147+
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "graphql/{*path}")] HttpRequest req,
148+
```
149+
150+
2. If you use the standard AzureFunctions configuration and map your function to Route to `graphql/{*path}` then you are done.
151+
However if you have changed either the default Azure Function prefix (which is `/api/`) or use a different Route binding, then youTo enable the Playground the Azure Function must be configured properly to serve all Web Assets dynamically
152+
need to explicitly tell the AzureFunctionsProxy what the expected base Url path is, so that the HC Middleware will successfully
153+
match the path and serve resources.
154+
- This is done easily by setting the `AzureFunctionsRoutePath` option in the configuration as follows:
155+
- Assuming the following then the configuration would be as follows:
156+
- You have changed the default Azure Functions prefix from `api` to `my-api` in the `host.json` file.
157+
- You have added a version `v1` in front of the Route binding and renamed it so your Route binding is now: `Route = "v1/graphql-service/{*path}"
158+
- *NOTE: you MUST still use the wildcard path matching for Playground to function properly.*
159+
```csharp
160+
//Finally Initialize AzureFunctions Executor Proxy here...
161+
services.AddAzureFunctionsGraphQL((options) =>
162+
{
163+
//When accessing the GraphQL via AzureFunctions this is the path that all Urls will be prefixed with
164+
// as configured in the AzureFunction host.json combined with the HttpTrigger Route binding.
165+
options.AzureFunctionsRoutePath = "/api/v1/graphql-service";
166+
});
167+
```
168+
169+
118170
## Disclaimers:
171+
* PlayGround & Schema Download Functionality:
172+
- There is one key reason that Playground and Schema Download works -- because the DEFAULT values for the GraphQL Options are to Enable them!
173+
- At this time the AzureFunctionsProxy can enablee/disable the middleware by either wiring up the Middleware or not.
174+
- But, the HC middleware checks for GraphQL configured options that are set at Configuration build time to see if these are enable/disabled,
175+
and that is stored on *Endpoint Metadata* that is not accessible (to my knowledge so far) in the Azure Function
176+
- This is because in Azure Functions (V2) we do not control the routing configuration at the same level of control that
177+
an Asp.Net Core application has.
178+
- However, since the HC defaults are to be `Enabled = true` then it's a non-issue!
119179
* Subscriptsion were disabled in the example project due to unknown supportability in a
120180
serverless environment.
121181
* The StarWars example uses in-memory subscriptions which are incongruent with the serverless

0 commit comments

Comments
 (0)