Skip to content

Instantly share code, notes, and snippets.

@xperiandri
Last active February 13, 2022 22:03
Show Gist options
  • Save xperiandri/98aa90c161faa12a9536f99584d79ad9 to your computer and use it in GitHub Desktop.
Save xperiandri/98aa90c161faa12a9536f99584d79ad9 to your computer and use it in GitHub Desktop.
// F#
type public GraphQLFunction (serviceProvider : IServiceProvider, log : ILogger<GraphQLFunction>) =
[<FunctionName "GraphQL">]
member public __.Execute
([<HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = null)>] req : HttpRequest,
cancellationToken : CancellationToken) = Async.StartAsTask (async {
let! responseData = GraphQL.handleRequest serviceProvider req.Body
let responseBody = GraphQLFunction.GetBody log responseData
return JsonResult (responseBody)
}, cancellationToken = cancellationToken)
// C#
public class GraphQLFunction (IServiceProvider: serviceProvider, ILogger<GraphQLFunction>: log)
{
[FunctionName("GraphQL")]
public Task Execute
([HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = null)] HttpRequest: req,
CancellationToken: cancellationToken)
{
var responseData = await GraphQL.HandleRequest(serviceProvider, req.Body, cancellationToken)
var responseBody = GraphQLFunction.GetBody(log, responseData)
return new JsonResult (responseBody)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment