GraphQL API Server
The squid data can be presented with a GraphQL API. The OpenReader server takes the schema file as an input argument and starts a GraphQL API serving OpenCRUD read queries for the entities defined in the schema.
To start the API server:
npx make serve
The API server listens at port defined by GQL_PORT
(default to 4350
). The database connection is configured with the env variables DB_NAME
, DB_USER
, DB_PASS
, DB_HOST
, DB_PORT
.
The API server is automatically started when the squid is deployed to the Aquarium.
Supported Queries
The details of the supported OpenReader queries can be found in a separate section Query a Squid. 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
- a "get one" query for
@unique
fields, with the name{entityName}ByUniqueInput
- a lookup query with the name
{entityName}s
. It supports filtering on each entity field with awhere
parameter, predicate compositions withAND
andOR
and limiting with theoffset
andlimit
parameters. - a GraphQL Cursor pagination query with the name
{entityName}sConnection
Nested queries are supported out-of-the-box for entity relations:
- for the
one
side of a relation,where
supports filtering on any field of the related entity - for the
many
side of a relation,where
supports filtersXXX_some
,XXX_every
andXXX_none
that match only if at least one (resp. each and none) of the related entities match the predicate.
Union and typed JSON types are mapped into GraphQL Union Types with a proper type resolution with __typename
.
Built-in custom scalars
The OpenReader GraphQL API defines the following custom scalars in the GraphQL to present the corresponding entity fields:
DateTime
:DateTime
fields in the schema are presented in the ISO formatBytes
:Bytes
fields are presented as hex-encoded strings prefixed with0x
BigInt
:BigInt
fields are presented as strings