Step by step instructions to implement this solution by Luigi Servini in the Fauna forums.
- Save schema.graphql from this gist on your machine.
- Create a new database in the Fauna dashboard.
- On the GraphQL tab, choose Import Schema then upload schema.graphql.
- On the Collections tab, select the Counter collection and choose New Document to create a new document. Copy and paste the contents of counter.json then choose Save.
- Copy the ID of the new document, e.g., 294683317926625795.
- On the Functions tab, select the user-defined function (UDF) increment_counter. Copy the code from increment_counter.fql and paste it into Function Body. Replace <document_id> with the document ID you copied in the previous step and choose Save.
- Return to the GraphQL tab, copy the GraphQL query from query.graphql, and paste the query in the GraphQL playground. When you run your query you should receive:
{
"data": {
"nextCounter": {
"counter": 1
}
}
}