Currently, querying ArangoDB with GraphQL requires building a GraphQL.js schema. This is tedious and the resulting JavaScript schema file can be long and bulky. Here we will demonstrate a short proof of concept that reduces the user related part to only defining the GraphQL IDL file and simple AQL queries.

The Apollo GraphQL project built a library that takes a GraphQL IDL and resolver functions to build a GraphQL.js schema. Resolve functions are called by GraphQL to get the actual data from the database. I modified the library in the way that before the resolvers are added, I read the IDL AST and create resolver functions.

To simplify things and to not depend on special “magic”, let’s introduce the directive @aql. With this directive, it’s possible to write an AQL query that gets the needed data. With the bind parameter @current it is possible to access the current parent object to do JOINs or related operations.

New to multi-model and graphs? Check out our free ArangoDB Graph Course.

Interested in trying out ArangoDB? Fire up your database in just a few clicks with ArangoDB Oasis: the Cloud Service for ArangoDB. Start your free 14-day trial here.


This IDL describes a BlogEntry and an Author object. The BlogEntry holds an Author object which is fetched via the AQL query in the directive @aql. The type Query defines a query that fetches one BlogEntry.

Now let’s have a look at a GraphQL query:

This query fetches the BlogEntry with _key “1”. The generated AQL query is:

And with the fetched BlogEntry document the corresponding Author is fetched via the AQL query defined in the directive.

The result will approximately look like this:

As a conclusion of this short demo, we can claim that with the usage of GraphQLs IDL, it is possible to reduce effort on the users’ side to query ArangoDB with GraphQL. For simple GraphQL queries and IDLs it’s possible to automatically generate resolvers to fetch the necessary data.

The effort resulted in an npm package is called graphql-aql-generator.

ArangoDB Foxx example

Now let’s have a look at the same example, but with using ArangoDB javascript framework – Foxx. To do so, we have to follow the simple steps listed below:

  1. Open the ArangoDB web interface and navigate to SERVICES.
  2. Then click Add Service. Select New Service and fill out all fields with *.
    Important is the Mount field. I will use /test. Then Generate.
  3. Click on the service to open its settings. Click Settings and then go to Set Development to enable the development mode.
  4. Then click Info and open the path at Path:.

Now we have to install the npm package:

We also need the collections Author and BlogEntry. And the following documents:

  • Author collection:

  • BlogEntry collection:

Foxx has a built-in graphql router that we can use to serve GraphQL queries. We assemble a new route called /graphql that serves the incoming GraphQL queries. With graphiql: true we enable the GraphiQL explorer so we can test-drive our queries.

Open and the GraphiQL explorer is loaded so we can execute a query to fetch a BlogEntry with an Author.

For the sake of completeness, here is the full Foxx example that works by copy & paste. Do not forget to
npm install graphql-aql-generator and create the collections and documents.

Would be great to hear your thoughts, feedback, questions, and comments in our Slack Community channel or via a contact us form.