> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sqd.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenReader Server Overview

> OpenReader is the open source GraphQL server bundled — generates an OpenCRUD-style API from your schema.graphql with caching and DoS protection.

<Info>
  OpenReader is no longer recommended for use in new squid projects [relying on PostgreSQL](/en/sdk/squid-sdk/resources/persisting-data/typeorm). See [Serving GraphQL](/en/sdk/squid-sdk/resources/serving-graphql) to learn about the new options and the [Limitations](#limitations) section to understand our motivation.
</Info>

OpenReader is a server that presents data of PostgreSQL-powered squids as a GraphQL API. It relies on the [eponymous library](https://github.com/subsquid/squid-sdk/tree/master/graphql/openreader) lib of the Squid SDK for schema generation. [Schema file](/en/sdk/squid-sdk/reference/schema-file) is used as an input; the resulting API supports [OpenCRUD](https://www.opencrud.org/) queries for the entities defined in the schema.

To start the API server based on `schema.graphql` install `@subsquid/graphql-server` and run the following in the squid project root:

```bash theme={"system"}
npx squid-graphql-server
```

The `squid-graphql-server` executable supports multiple optional flags to enable [caching](/en/sdk/squid-sdk/reference/openreader-server/configuration/caching), [subscriptions](/en/sdk/squid-sdk/reference/openreader-server/configuration/subscriptions), [DoS protection](/en/sdk/squid-sdk/reference/openreader-server/configuration/dos-protection) etc. Its features are covered in the next sections.

The API server listens at port defined by the `GQL_PORT` environment variable (defaults to `4350`). The database connection is configured with the env variables `DB_NAME`, `DB_USER`, `DB_PASS`, `DB_HOST`, `DB_PORT`.

In [SQD Cloud](/en/cloud), OpenReader is usually ran as the `api:` service in the `deploy:` section of the [Deployment manifest](/en/cloud/reference/manifest).

## Supported queries

The details of the supported OpenReader queries can be found in a separate section [Core API](/en/sdk/squid-sdk/reference/openreader-server/api). Here is a brief overview of the queries generated by OpenReader for each entity defined in the schema file:

* the squid last processed block is available with `squidStatus { height }` query
* a "get one by ID" query with the name `{entityName}ById` for each [entity](/en/sdk/squid-sdk/reference/schema-file/entities) defined in the schema file
* a "get one" query for [`@unique` fields](/en/sdk/squid-sdk/reference/schema-file/indexes-and-constraints), with the name `{entityName}ByUniqueInput`
* Entity queries named `{entityName}sConnection`. Each query supports rich filtering support, including [field-level filters](/en/sdk/squid-sdk/reference/openreader-server/api/queries), composite [`AND` and `OR` filters](/en/sdk/squid-sdk/reference/openreader-server/api/and-or-filters), [nested queries](/en/sdk/squid-sdk/reference/openreader-server/api/nested-field-queries), [cross-relation queries](/en/sdk/squid-sdk/reference/openreader-server/api/cross-relation-field-queries) and [Relay-compatible](https://relay.dev/graphql/connections.htm) cursor-based [pagination](/en/sdk/squid-sdk/reference/openreader-server/api/paginate-query-results).
* [Subsriptions](/en/sdk/squid-sdk/reference/openreader-server/configuration/subscriptions) via live queries
* (Deprecated in favor of Relay connections) Lookup queries with the name `{entityName}s`.

[Union and typed JSON types](/en/sdk/squid-sdk/reference/schema-file/unions-and-typed-json) are mapped into [GraphQL Union Types](https://graphql.org/learn/schema/#union-types) with a [proper type resolution](/en/sdk/squid-sdk/reference/openreader-server/api/resolve-union-types-interfaces) with `__typename`.

## Built-in custom scalar types

The OpenReader GraphQL API defines the following custom scalar types:

* `DateTime` entity field values are presented in the ISO format
* `Bytes` entity field values are presented as hex-encoded strings prefixed with `0x`
* `BigInt` entity field values are presented as strings

## Limitations

* RAM usage of [subscriptions](/en/sdk/squid-sdk/reference/openreader-server/configuration/subscriptions) scales poorly under high load, making the feature unsuitable for most production uses. There are currently no plans to fix this issue.
* Setting up custom resolvers for subscriptions is unreasonably hard.
* `@subsquid/graphql-server` depends on the deprecated Apollo Server v3.
