Looking for Cloud Services or Professional Support? Check restheart.com

Edit Page

GraphQL API Overview

The restheart-graphql plugin provides a read-only GraphQL API for MongoDB, complementing the REST API for modern applications.

Queries are made through HTTP POST requests with application/json or application/graphql content types, and responses are in application/graphql-response+json format.

Key Points:

  • Supports all GraphQL types: type, query, enum, interface, union, and input.

  • GraphQL applications require a JSON document, the GraphQL app definition, stored in the /graphql collection.

  • App definition includes Descriptor (app name, description, enabled status, URI), Schema (GraphQL SDL), and Mappings (connecting types to MongoDB data).

  • Mappings include Field-to-Field (mapping GraphQL to MongoDB fields), Field-to-Query (connecting GraphQL Object field to MongoDB query), and Field-to-Aggregation (linking GraphQL Object field to MongoDB aggregation stages).

  • Mappings leverage $arg and $fk operators for flexibility in handling GraphQL arguments and traversing related documents.

  • Support for features like Optional Stages, Arguments with Default Values, and rootDoc Argument for crafting queries and aggregations.

  • Extends GraphQL typing system for MongoDB data types (e.g., BsonObjectId, BsonDocument).

  • Provide automatically schema fetching for query autocompletion and syntax checking in popular clients like Postman and Insomnia.

  • Provide an optimization feature that mitigates the N+1 requests problem.

Try It Yourself!

Why not put your knowledge into practice? Follow the GraphQL RESTHeart Tutorial!