Using with Graphql?


#1

Hey!

I recently started using AWS AppSync which is a Graphql API as a service.

I thought it would be cool if you could create scripts that:

  1. Set ups a haskell lambda (using https://github.com/Nike-Inc/hal)

The default interpreter is just a function that takes some json input and transforms it to some json output

  1. Ensure that the types between the AppSync schema and lambda are synced.

Since a graphql query is basically just a function, it should be possible to define a translation from a dhall object, say

let Input: Type = {
name: Text,
email: Text,
age: Natural
}

let Output: Type = Text

To a graphql query

myLambdaFunction(input: Input): Output

Then you could also write scripts to generate correct resolvers and data sources using cloudformation, import that same type in Haskell using dhall+template haskell and that way you can safely ensure that the graphql schema is correct.

Would this be possible in dhall?


#2

I am interpreting this question as: can we use Dhall as an interface definition language (IDL) that we can generate code from so that, say, an AWS Lambda service and an AWS AppSync service remain in sync? If I understood the question wrong, just let me know.

The answer is: yes. For example, the Haskell bindings to Dhall provide a Dhall.inputExpr function which will let you import a Dhall type as a Haskell syntax tree. Then you could write a Haskell program that takes that syntax tree as input and generates the desired output code or configuration files.