Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
apollo-datasource-configurable-rest
Advanced tools
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.
yarn add apollo-datasource-configurable-rest
# or
npm i apollo-datasource-configurable-rest
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.
The following example shows how to configure a get request with url params and headers:
import { ConfigurableRESTDataSource } from 'apollo-datasource-configurable-rest'
export class MyRestDatasource extends ConfigurableRESTDataSource {
// $book will be replaced by the query argument named "book"
baseURL = 'https://api.com/texts/$book'
// if your query contains optional arguments
// you can set a default value for these arguments here
defaultArgs = {
book: 'title-of-book'
language: 'de',
chapter: 1,
}
// url parameter definitions
// with the default arguments this would result in:
// https://api.com/texts/title-of-book?lng=de&chapter=1
params = {
lng: "$language",
chapter: "$chapter",
}
// header definitions
// the $accessToken keyword would replaced by
// the query argument named "accessToken"
headers = {
Authorization: 'Bearer $accessToken',
'Content-Type': 'application/json',
}
// this is for your resolver
async fetchChapters(args: QueryArgs) {
// the configuredGET command now replaces the arguments
// in the url, parameters and headers and fetches the api
return this.configuredGET(args)
}
}
There are fetchers GET
, DELETE
, POST
, PUT
and PATCH
.
async configuredGET<TResult = any>(args: Partial<TArgs>, options?: RequestInitOptions): Promise<TResult>
async configuredDELETE<TResult = any>(args: Partial<TArgs>, options?: RequestInitOptions): Promise<TResult>
async configuredPOST<TResult = any>(args: Partial<TArgs>, body?: Body): Promise<TResult>
async configuredPUT<TResult = any>(args: Partial<TArgs>, body?: Body): Promise<TResult>
async configuredPATCH<TResult = any>(args: Partial<TArgs>, body?: Body): Promise<TResult>
You can configure a cache time for the GET
and DELETE
fetcher:
public fetchChapters(args: QueryArgs) {
this.configuredGET(args, { cacheTime: 3000 })
}
You can define typings for your query arguments, url parameters, headers and body definitions:
import { ConfigurableRESTDataSource } from 'apollo-datasource-configurable-rest'
type QueryArgs = {
book?: string,
language?: string,
chapter?: number,
accessToken: string,
}
type Params = {
lng: string,
chapter: number,
}
type Headers = {
Authorization: string
}
type Body = {
myBody: {
structure: string,
num: number,
}
}
export class MyRestDatasource extends ConfigurableRESTDataSource<
QueryArgs, Params, Headers, Body
> {
// ...
}
FAQs
configurable rest datasource
The npm package apollo-datasource-configurable-rest receives a total of 1 weekly downloads. As such, apollo-datasource-configurable-rest popularity was classified as not popular.
We found that apollo-datasource-configurable-rest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.