├── .gitignore
├── GraphQL-AzureFunctions-HotChocolate.sln
├── LICENSE
├── README.md
└── src
├── .gitignore
├── GraphQL-AzureFunctions-HotChocolate.csproj
├── GraphQL.cs
├── HotChocolate.AzureFunctionsMiddleware
├── AzureFunctionsMiddlewareExtension.cs
├── AzureFunctionsMiddlewareOptions.cs
├── GraphQLFunctions.cs
├── IAzureFunctionsMiddlewareOptions.cs
└── IGraphQLFunctions.cs
├── StarWars
├── Data
│ ├── CharacterRepository.cs
│ └── ReviewRepository.cs
├── Models
│ ├── Droid.cs
│ ├── Episode.cs
│ ├── Human.cs
│ ├── ICharacter.cs
│ ├── Review.cs
│ ├── Starship.cs
│ └── Unit.cs
├── Query.cs
├── Resolvers
│ └── SharedResolvers.cs
└── Types
│ ├── CharacterType.cs
│ ├── DroidType.cs
│ ├── EpisodeType.cs
│ ├── HumanType.cs
│ ├── QueryType.cs
│ ├── ReviewInputType.cs
│ ├── ReviewType.cs
│ ├── SearchResultType.cs
│ ├── StarshipType.cs
│ └── UnitType.cs
├── Startup.cs
├── host.json
└── local.settings.json
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.svclog
86 | *.scc
87 |
88 | # Chutzpah Test files
89 | _Chutzpah*
90 |
91 | # Visual C++ cache files
92 | ipch/
93 | *.aps
94 | *.ncb
95 | *.opendb
96 | *.opensdf
97 | *.sdf
98 | *.cachefile
99 | *.VC.db
100 | *.VC.VC.opendb
101 |
102 | # Visual Studio profiler
103 | *.psess
104 | *.vsp
105 | *.vspx
106 | *.sap
107 |
108 | # Visual Studio Trace Files
109 | *.e2e
110 |
111 | # TFS 2012 Local Workspace
112 | $tf/
113 |
114 | # Guidance Automation Toolkit
115 | *.gpState
116 |
117 | # ReSharper is a .NET coding add-in
118 | _ReSharper*/
119 | *.[Rr]e[Ss]harper
120 | *.DotSettings.user
121 |
122 | # JustCode is a .NET coding add-in
123 | .JustCode
124 |
125 | # TeamCity is a build add-in
126 | _TeamCity*
127 |
128 | # DotCover is a Code Coverage Tool
129 | *.dotCover
130 |
131 | # AxoCover is a Code Coverage Tool
132 | .axoCover/*
133 | !.axoCover/settings.json
134 |
135 | # Visual Studio code coverage results
136 | *.coverage
137 | *.coveragexml
138 |
139 | # NCrunch
140 | _NCrunch_*
141 | .*crunch*.local.xml
142 | nCrunchTemp_*
143 |
144 | # MightyMoose
145 | *.mm.*
146 | AutoTest.Net/
147 |
148 | # Web workbench (sass)
149 | .sass-cache/
150 |
151 | # Installshield output folder
152 | [Ee]xpress/
153 |
154 | # DocProject is a documentation generator add-in
155 | DocProject/buildhelp/
156 | DocProject/Help/*.HxT
157 | DocProject/Help/*.HxC
158 | DocProject/Help/*.hhc
159 | DocProject/Help/*.hhk
160 | DocProject/Help/*.hhp
161 | DocProject/Help/Html2
162 | DocProject/Help/html
163 |
164 | # Click-Once directory
165 | publish/
166 |
167 | # Publish Web Output
168 | *.[Pp]ublish.xml
169 | *.azurePubxml
170 | # Note: Comment the next line if you want to checkin your web deploy settings,
171 | # but database connection strings (with potential passwords) will be unencrypted
172 | *.pubxml
173 | *.publishproj
174 |
175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
176 | # checkin your Azure Web App publish settings, but sensitive information contained
177 | # in these scripts will be unencrypted
178 | PublishScripts/
179 |
180 | # NuGet Packages
181 | *.nupkg
182 | # The packages folder can be ignored because of Package Restore
183 | **/[Pp]ackages/*
184 | # except build/, which is used as an MSBuild target.
185 | !**/[Pp]ackages/build/
186 | # Uncomment if necessary however generally it will be regenerated when needed
187 | #!**/[Pp]ackages/repositories.config
188 | # NuGet v3's project.json files produces more ignorable files
189 | *.nuget.props
190 | *.nuget.targets
191 |
192 | # Microsoft Azure Build Output
193 | csx/
194 | *.build.csdef
195 |
196 | # Microsoft Azure Emulator
197 | ecf/
198 | rcf/
199 |
200 | # Windows Store app package directories and files
201 | AppPackages/
202 | BundleArtifacts/
203 | Package.StoreAssociation.xml
204 | _pkginfo.txt
205 | *.appx
206 |
207 | # Visual Studio cache files
208 | # files ending in .cache can be ignored
209 | *.[Cc]ache
210 | # but keep track of directories ending in .cache
211 | !*.[Cc]ache/
212 |
213 | # Others
214 | ClientBin/
215 | ~$*
216 | *~
217 | *.dbmdl
218 | *.dbproj.schemaview
219 | *.jfm
220 | *.pfx
221 | *.publishsettings
222 | orleans.codegen.cs
223 |
224 | # Including strong name files can present a security risk
225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
226 | #*.snk
227 |
228 | # Since there are multiple workflows, uncomment next line to ignore bower_components
229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
230 | #bower_components/
231 |
232 | # RIA/Silverlight projects
233 | Generated_Code/
234 |
235 | # Backup & report files from converting an old project file
236 | # to a newer Visual Studio version. Backup files are not needed,
237 | # because we have git ;-)
238 | _UpgradeReport_Files/
239 | Backup*/
240 | UpgradeLog*.XML
241 | UpgradeLog*.htm
242 | ServiceFabricBackup/
243 | *.rptproj.bak
244 |
245 | # SQL Server files
246 | *.mdf
247 | *.ldf
248 | *.ndf
249 |
250 | # Business Intelligence projects
251 | *.rdl.data
252 | *.bim.layout
253 | *.bim_*.settings
254 | *.rptproj.rsuser
255 |
256 | # Microsoft Fakes
257 | FakesAssemblies/
258 |
259 | # GhostDoc plugin setting file
260 | *.GhostDoc.xml
261 |
262 | # Node.js Tools for Visual Studio
263 | .ntvs_analysis.dat
264 | node_modules/
265 |
266 | # Visual Studio 6 build log
267 | *.plg
268 |
269 | # Visual Studio 6 workspace options file
270 | *.opt
271 |
272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
273 | *.vbw
274 |
275 | # Visual Studio LightSwitch build output
276 | **/*.HTMLClient/GeneratedArtifacts
277 | **/*.DesktopClient/GeneratedArtifacts
278 | **/*.DesktopClient/ModelManifest.xml
279 | **/*.Server/GeneratedArtifacts
280 | **/*.Server/ModelManifest.xml
281 | _Pvt_Extensions
282 |
283 | # Paket dependency manager
284 | .paket/paket.exe
285 | paket-files/
286 |
287 | # FAKE - F# Make
288 | .fake/
289 |
290 | # JetBrains Rider
291 | .idea/
292 | *.sln.iml
293 |
294 | # CodeRush
295 | .cr/
296 |
297 | # Python Tools for Visual Studio (PTVS)
298 | __pycache__/
299 | *.pyc
300 |
301 | # Cake - Uncomment if you are using it
302 | # tools/**
303 | # !tools/packages.config
304 |
305 | # Tabs Studio
306 | *.tss
307 |
308 | # Telerik's JustMock configuration file
309 | *.jmconfig
310 |
311 | # BizTalk build output
312 | *.btp.cs
313 | *.btm.cs
314 | *.odx.cs
315 | *.xsd.cs
316 |
317 | # OpenCover UI analysis results
318 | OpenCover/
319 |
320 | # Azure Stream Analytics local run output
321 | ASALocalRun/
322 |
323 | # MSBuild Binary and Structured Log
324 | *.binlog
325 |
326 | # NVidia Nsight GPU debugger configuration file
327 | *.nvuser
328 |
329 | # MFractors (Xamarin productivity tool) working folder
330 | .mfractor/
331 |
--------------------------------------------------------------------------------
/GraphQL-AzureFunctions-HotChocolate.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.28803.202
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL-AzureFunctions-HotChocolate", "src\GraphQL-AzureFunctions-HotChocolate.csproj", "{2C99C332-EFDC-4A14-975E-948F56EBFBDF}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {2C99C332-EFDC-4A14-975E-948F56EBFBDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {2C99C332-EFDC-4A14-975E-948F56EBFBDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {2C99C332-EFDC-4A14-975E-948F56EBFBDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {2C99C332-EFDC-4A14-975E-948F56EBFBDF}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {4B9C23F1-4D04-499D-B6B5-75A53EA886AA}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Daniel Gut
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GraphQL-AzureFunctions-HotChocolate
2 | running a HotChocolate GraphQL server in Azure Functions
3 |
--------------------------------------------------------------------------------
/src/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # Azure Functions localsettings file
5 | local.settings.json
6 |
7 | # User-specific files
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | bld/
24 | [Bb]in/
25 | [Oo]bj/
26 | [Ll]og/
27 |
28 | # Visual Studio 2015 cache/options directory
29 | .vs/
30 | # Uncomment if you have tasks that create the project's static files in wwwroot
31 | #wwwroot/
32 |
33 | # MSTest test Results
34 | [Tt]est[Rr]esult*/
35 | [Bb]uild[Ll]og.*
36 |
37 | # NUNIT
38 | *.VisualState.xml
39 | TestResult.xml
40 |
41 | # Build Results of an ATL Project
42 | [Dd]ebugPS/
43 | [Rr]eleasePS/
44 | dlldata.c
45 |
46 | # DNX
47 | project.lock.json
48 | project.fragment.lock.json
49 | artifacts/
50 |
51 | *_i.c
52 | *_p.c
53 | *_i.h
54 | *.ilk
55 | *.meta
56 | *.obj
57 | *.pch
58 | *.pdb
59 | *.pgc
60 | *.pgd
61 | *.rsp
62 | *.sbr
63 | *.tlb
64 | *.tli
65 | *.tlh
66 | *.tmp
67 | *.tmp_proj
68 | *.log
69 | *.vspscc
70 | *.vssscc
71 | .builds
72 | *.pidb
73 | *.svclog
74 | *.scc
75 |
76 | # Chutzpah Test files
77 | _Chutzpah*
78 |
79 | # Visual C++ cache files
80 | ipch/
81 | *.aps
82 | *.ncb
83 | *.opendb
84 | *.opensdf
85 | *.sdf
86 | *.cachefile
87 | *.VC.db
88 | *.VC.VC.opendb
89 |
90 | # Visual Studio profiler
91 | *.psess
92 | *.vsp
93 | *.vspx
94 | *.sap
95 |
96 | # TFS 2012 Local Workspace
97 | $tf/
98 |
99 | # Guidance Automation Toolkit
100 | *.gpState
101 |
102 | # ReSharper is a .NET coding add-in
103 | _ReSharper*/
104 | *.[Rr]e[Ss]harper
105 | *.DotSettings.user
106 |
107 | # JustCode is a .NET coding add-in
108 | .JustCode
109 |
110 | # TeamCity is a build add-in
111 | _TeamCity*
112 |
113 | # DotCover is a Code Coverage Tool
114 | *.dotCover
115 |
116 | # NCrunch
117 | _NCrunch_*
118 | .*crunch*.local.xml
119 | nCrunchTemp_*
120 |
121 | # MightyMoose
122 | *.mm.*
123 | AutoTest.Net/
124 |
125 | # Web workbench (sass)
126 | .sass-cache/
127 |
128 | # Installshield output folder
129 | [Ee]xpress/
130 |
131 | # DocProject is a documentation generator add-in
132 | DocProject/buildhelp/
133 | DocProject/Help/*.HxT
134 | DocProject/Help/*.HxC
135 | DocProject/Help/*.hhc
136 | DocProject/Help/*.hhk
137 | DocProject/Help/*.hhp
138 | DocProject/Help/Html2
139 | DocProject/Help/html
140 |
141 | # Click-Once directory
142 | publish/
143 |
144 | # Publish Web Output
145 | *.[Pp]ublish.xml
146 | *.azurePubxml
147 | # TODO: Comment the next line if you want to checkin your web deploy settings
148 | # but database connection strings (with potential passwords) will be unencrypted
149 | #*.pubxml
150 | *.publishproj
151 |
152 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
153 | # checkin your Azure Web App publish settings, but sensitive information contained
154 | # in these scripts will be unencrypted
155 | PublishScripts/
156 |
157 | # NuGet Packages
158 | *.nupkg
159 | # The packages folder can be ignored because of Package Restore
160 | **/packages/*
161 | # except build/, which is used as an MSBuild target.
162 | !**/packages/build/
163 | # Uncomment if necessary however generally it will be regenerated when needed
164 | #!**/packages/repositories.config
165 | # NuGet v3's project.json files produces more ignoreable files
166 | *.nuget.props
167 | *.nuget.targets
168 |
169 | # Microsoft Azure Build Output
170 | csx/
171 | *.build.csdef
172 |
173 | # Microsoft Azure Emulator
174 | ecf/
175 | rcf/
176 |
177 | # Windows Store app package directories and files
178 | AppPackages/
179 | BundleArtifacts/
180 | Package.StoreAssociation.xml
181 | _pkginfo.txt
182 |
183 | # Visual Studio cache files
184 | # files ending in .cache can be ignored
185 | *.[Cc]ache
186 | # but keep track of directories ending in .cache
187 | !*.[Cc]ache/
188 |
189 | # Others
190 | ClientBin/
191 | ~$*
192 | *~
193 | *.dbmdl
194 | *.dbproj.schemaview
195 | *.jfm
196 | *.pfx
197 | *.publishsettings
198 | node_modules/
199 | orleans.codegen.cs
200 |
201 | # Since there are multiple workflows, uncomment next line to ignore bower_components
202 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
203 | #bower_components/
204 |
205 | # RIA/Silverlight projects
206 | Generated_Code/
207 |
208 | # Backup & report files from converting an old project file
209 | # to a newer Visual Studio version. Backup files are not needed,
210 | # because we have git ;-)
211 | _UpgradeReport_Files/
212 | Backup*/
213 | UpgradeLog*.XML
214 | UpgradeLog*.htm
215 |
216 | # SQL Server files
217 | *.mdf
218 | *.ldf
219 |
220 | # Business Intelligence projects
221 | *.rdl.data
222 | *.bim.layout
223 | *.bim_*.settings
224 |
225 | # Microsoft Fakes
226 | FakesAssemblies/
227 |
228 | # GhostDoc plugin setting file
229 | *.GhostDoc.xml
230 |
231 | # Node.js Tools for Visual Studio
232 | .ntvs_analysis.dat
233 |
234 | # Visual Studio 6 build log
235 | *.plg
236 |
237 | # Visual Studio 6 workspace options file
238 | *.opt
239 |
240 | # Visual Studio LightSwitch build output
241 | **/*.HTMLClient/GeneratedArtifacts
242 | **/*.DesktopClient/GeneratedArtifacts
243 | **/*.DesktopClient/ModelManifest.xml
244 | **/*.Server/GeneratedArtifacts
245 | **/*.Server/ModelManifest.xml
246 | _Pvt_Extensions
247 |
248 | # Paket dependency manager
249 | .paket/paket.exe
250 | paket-files/
251 |
252 | # FAKE - F# Make
253 | .fake/
254 |
255 | # JetBrains Rider
256 | .idea/
257 | *.sln.iml
258 |
259 | # CodeRush
260 | .cr/
261 |
262 | # Python Tools for Visual Studio (PTVS)
263 | __pycache__/
264 | *.pyc
--------------------------------------------------------------------------------
/src/GraphQL-AzureFunctions-HotChocolate.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netcoreapp3.1
4 | v3
5 | GraphQL_AzureFunctions_HotChocolate
6 | <_FunctionsSkipCleanOutput>true
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | PreserveNewest
17 |
18 |
19 | PreserveNewest
20 | Never
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/GraphQL.cs:
--------------------------------------------------------------------------------
1 | using HotChocolate.AzureFunctions;
2 | using Microsoft.AspNetCore.Http;
3 | using Microsoft.AspNetCore.Mvc;
4 | using Microsoft.Azure.WebJobs;
5 | using Microsoft.Azure.WebJobs.Extensions.Http;
6 | using Microsoft.Extensions.Logging;
7 | using System.Threading;
8 | using System.Threading.Tasks;
9 |
10 | namespace GraphQLAzureFunctions
11 | {
12 | public class GraphQL
13 | {
14 | private readonly IGraphQLFunctions _graphQLFunctions;
15 |
16 | public GraphQL(IGraphQLFunctions graphQLFunctions)
17 | {
18 | _graphQLFunctions = graphQLFunctions;
19 | }
20 |
21 | [FunctionName("graphql")]
22 | public async Task Run(
23 | [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
24 | ILogger log, CancellationToken cancellationToken)
25 | {
26 | return await _graphQLFunctions.ExecuteFunctionsQueryAsync(
27 | req.HttpContext,
28 | cancellationToken);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/HotChocolate.AzureFunctionsMiddleware/AzureFunctionsMiddlewareExtension.cs:
--------------------------------------------------------------------------------
1 | using HotChocolate.AzureFunctions;
2 | using Microsoft.Extensions.DependencyInjection;
3 |
4 | namespace HotChocolate.AspNetCore
5 | {
6 | public static class AzureFunctionsMiddlewareExtension
7 | {
8 | public static IServiceCollection AddAzureFunctionsGraphQL(
9 | this IServiceCollection serviceCollection,
10 | IAzureFunctionsMiddlewareOptions options)
11 | {
12 | serviceCollection.AddSingleton(options);
13 |
14 | serviceCollection.AddSingleton();
15 |
16 | return serviceCollection;
17 | }
18 |
19 | public static IServiceCollection AddAzureFunctionsGraphQL(
20 | this IServiceCollection serviceCollection)
21 | {
22 | serviceCollection.AddAzureFunctionsGraphQL(new AzureFunctionsMiddlewareOptions());
23 |
24 | return serviceCollection;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/HotChocolate.AzureFunctionsMiddleware/AzureFunctionsMiddlewareOptions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using HotChocolate.Language;
3 | using Microsoft.AspNetCore.Http;
4 |
5 | namespace HotChocolate.AspNetCore
6 | {
7 | public class AzureFunctionsMiddlewareOptions
8 | : IAzureFunctionsMiddlewareOptions
9 | {
10 | private const int _minMaxRequestSize = 1024;
11 | private ParserOptions _parserOptions = new ParserOptions();
12 | private int _maxRequestSize = 20 * 1000 * 1000;
13 |
14 | public ParserOptions ParserOptions
15 | {
16 | get => _parserOptions;
17 | set
18 | {
19 | if (value == null)
20 | {
21 | throw new ArgumentNullException(nameof(value));
22 | }
23 | _parserOptions = value;
24 | }
25 | }
26 |
27 | public int MaxRequestSize
28 | {
29 | get => _maxRequestSize;
30 | set
31 | {
32 | if (value < _minMaxRequestSize)
33 | {
34 | // TODO : resources
35 | throw new ArgumentException(
36 | "The minimum max request size is 1024 byte.",
37 | nameof(value));
38 | }
39 |
40 | _maxRequestSize = value;
41 | }
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/HotChocolate.AzureFunctionsMiddleware/GraphQLFunctions.cs:
--------------------------------------------------------------------------------
1 | using HotChocolate.AspNetCore;
2 | using HotChocolate.Execution;
3 | using HotChocolate.Language;
4 | using HotChocolate.Server;
5 | using Microsoft.AspNetCore.Http;
6 | using Microsoft.AspNetCore.Mvc;
7 | using System.IO;
8 | using System.Threading;
9 | using System.Threading.Tasks;
10 |
11 | namespace HotChocolate.AzureFunctions
12 | {
13 | public class GraphQLFunctions : IGraphQLFunctions
14 | {
15 | public IQueryExecutor Executor { get; }
16 | public IDocumentCache DocumentCache { get; }
17 | public IDocumentHashProvider DocumentHashProvider { get; }
18 | public IAzureFunctionsMiddlewareOptions AzureFunctionsOptions { get; }
19 | private readonly RequestHelper _requestHelper;
20 | private readonly JsonQueryResultSerializer _jsonQueryResultSerializer;
21 |
22 | public GraphQLFunctions(IQueryExecutor executor, IDocumentCache documentCache,
23 | IDocumentHashProvider documentHashProvider, IAzureFunctionsMiddlewareOptions azureFunctionsOptions /*JsonQueryResultSerializer jsonQueryResultSerializer*/)
24 | {
25 | Executor = executor;
26 | DocumentCache = documentCache;
27 | DocumentHashProvider = documentHashProvider;
28 | AzureFunctionsOptions = azureFunctionsOptions;
29 |
30 | _jsonQueryResultSerializer = new JsonQueryResultSerializer();
31 |
32 | _requestHelper = new RequestHelper(
33 | DocumentCache,
34 | DocumentHashProvider,
35 | AzureFunctionsOptions.MaxRequestSize,
36 | AzureFunctionsOptions.ParserOptions);
37 | }
38 |
39 | public async Task ExecuteFunctionsQueryAsync(
40 | HttpContext context,
41 | CancellationToken cancellationToken)
42 | {
43 | using var stream = context.Request.Body;
44 |
45 | var requestQuery = await _requestHelper
46 | .ReadJsonRequestAsync(stream, cancellationToken)
47 | .ConfigureAwait(false);
48 |
49 | var builder = QueryRequestBuilder.New();
50 |
51 | if (requestQuery.Count > 0)
52 | {
53 | var firstQuery = requestQuery[0];
54 |
55 | builder
56 | .SetQuery(firstQuery.Query)
57 | .SetOperation(firstQuery.OperationName)
58 | .SetQueryName(firstQuery.QueryName);
59 |
60 | if (firstQuery.Variables != null
61 | && firstQuery.Variables.Count > 0)
62 | {
63 | builder.SetVariableValues(firstQuery.Variables);
64 | }
65 | }
66 |
67 | var result = await Executor.ExecuteAsync(builder.Create());
68 | await _jsonQueryResultSerializer.SerializeAsync((IReadOnlyQueryResult)result, context.Response.Body);
69 |
70 | return new EmptyResult();
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/HotChocolate.AzureFunctionsMiddleware/IAzureFunctionsMiddlewareOptions.cs:
--------------------------------------------------------------------------------
1 | namespace HotChocolate.AspNetCore
2 | {
3 | public interface IAzureFunctionsMiddlewareOptions
4 | : IParserOptionsAccessor
5 | {
6 | int MaxRequestSize { get; }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/HotChocolate.AzureFunctionsMiddleware/IGraphQLFunctions.cs:
--------------------------------------------------------------------------------
1 | using HotChocolate.AspNetCore;
2 | using HotChocolate.Execution;
3 | using HotChocolate.Language;
4 | using Microsoft.AspNetCore.Http;
5 | using Microsoft.AspNetCore.Mvc;
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 |
9 | namespace HotChocolate.AzureFunctions
10 | {
11 | public interface IGraphQLFunctions
12 | {
13 | IAzureFunctionsMiddlewareOptions AzureFunctionsOptions { get; }
14 | IDocumentCache DocumentCache { get; }
15 | IDocumentHashProvider DocumentHashProvider { get; }
16 | IQueryExecutor Executor { get; }
17 | Task ExecuteFunctionsQueryAsync(
18 | HttpContext context,
19 | CancellationToken cancellationToken);
20 | }
21 | }
--------------------------------------------------------------------------------
/src/StarWars/Data/CharacterRepository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using StarWars.Models;
5 |
6 | namespace StarWars.Data
7 | {
8 | public class CharacterRepository
9 | {
10 | private Dictionary _characters;
11 | private Dictionary _starships;
12 |
13 | public CharacterRepository()
14 | {
15 | _characters = CreateCharacters().ToDictionary(t => t.Id);
16 | _starships = CreateStarships().ToDictionary(t => t.Id);
17 | }
18 |
19 | public ICharacter GetHero(Episode episode)
20 | {
21 | if (episode == Episode.Empire)
22 | {
23 | return _characters["1000"];
24 | }
25 | return _characters["2001"];
26 | }
27 |
28 | public ICharacter GetCharacter(string id)
29 | {
30 | if (_characters.TryGetValue(id, out ICharacter c))
31 | {
32 | return c;
33 | }
34 | return null;
35 | }
36 |
37 | public Human GetHuman(string id)
38 | {
39 | if (_characters.TryGetValue(id, out ICharacter c)
40 | && c is Human h)
41 | {
42 | return h;
43 | }
44 | return null;
45 | }
46 |
47 | public Droid GetDroid(string id)
48 | {
49 | if (_characters.TryGetValue(id, out ICharacter c)
50 | && c is Droid d)
51 | {
52 | return d;
53 | }
54 | return null;
55 | }
56 |
57 | public IEnumerable