Saturn
Saturn copied to clipboard
Investigate GraphQL controllers
Investigate abstraction for creating GraphQL instead of REST-ish controllers.
https://github.com/fsprojects/FSharp.Data.GraphQL may be of interest here.
Also of interest: https://graphql.org/learn/serving-over-http/
Summary:
- Single endpoint, usually
/graphql, handles all requests - Handle either GET or POST
- For GET, use query string. One parameter named
queryrequired, optional parameters can includevariables(JSON-encoded string) andoperationName(a single string). - For POST, request should use
application/jsoncontent type. Body is JSON with up to three fields:query,variables, andoperationName.queryis required, but might be specified in the URL query parameters rather than body; both should be accepted and handled.- Spec doesn't say what happens if URL has a query parameter named
queryand JSON body also has aqueryfield. In such a case, I'd suggest going with the behavior of the express-graphql library, which useslet query = urlData.query || bodyData.query;so that URL parameters, if specified, override the body. (Same applies tovariablesandoperationName.
- Spec doesn't say what happens if URL has a query parameter named
variablesonly required if query contains variables.operationNameonly required if query contains multiple operations.
- If
application/graphqlcontent type is used instead, POST body should be considered the GraphQL query string (andvariablesandoperationName, if presented, would have to be found in the URL query parameters) - Response should always be JSON, in format
{ "data": { ... }, "errors": [ ... ] }.errorsfield only present if there were errors, otherwise omitted.dataomitted if error happened before query execution began. If query execution started but error prevented response,datashould be present but containnull.
More formal spec: http://facebook.github.io/graphql/June2018/
3 years later, what is the recommended way of doing GraphQL with Saturn now? Is there any? Is it possible (in a production quality/setup)?
@AlexeyRaga Probably the best way right now is not to involve Saturn and use AspNetCore middleware from
- graphql-dotnet pretty solid and pretty popular but a bit too low-level in my experience (using this in production)
- hot chocolate newer solution than graphql-dotnet and removes a lot of boiler plate when mapping types (haven't tried it but it looks like it solves lots of issues that graphql-dotnet has)
- FSharp.Data.GraphQL native F# implementation of a GraphQL server that might need a bit of glue to hook into Saturn but it is also a bit low-level like graphql-dotnet
You will need to experiment with these to see which one suits your needs the best