Apollo Configurable REST Data Source
This rest datasource is an extension of apollo's rest data source. So you have all the options which come from apollo's rest data source and even more:
This extension aims to simplify data source definitions in your apollo server by configuring them via class parameters.
Installation
yarn add apollo-datasource-configurable-rest# or npm i apollo-datasource-configurable-rest
Usage
One key thought, besides the configuration via class parameter, is that all keywords which are prefixed with a $
are replaced by the query argument with the same name.
For example if you have a query argument named language
and you use $language
in your definitions it will be replaced by the query argument.
Simple example
The following example shows how to configure a get request with url params and headers:
Configured fetchers
There are fetchers GET
, DELETE
, POST
, PUT
and PATCH
.
async configuredGETargs: Partial<TArgs>, options?: RequestInitOptions: Promise<TResult> async configuredDELETEargs: Partial<TArgs>, options?: RequestInitOptions: Promise<TResult> async configuredPOSTargs: Partial<TArgs>, body?: Body: Promise<TResult> async configuredPUTargs: Partial<TArgs>, body?: Body: Promise<TResult> async configuredPATCHargs: Partial<TArgs>, body?: Body: Promise<TResult>
Caching
You can configure a cache time for the GET
and DELETE
fetcher:
public fetchChaptersargs: QueryArgs
Use Generics
You can define typings for your query arguments, url parameters, headers and body definitions: