Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-retrofit

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-retrofit - npm Package Compare versions

Comparing version 1.12.0 to 1.13.0

14

lib/baseService.js

@@ -209,2 +209,5 @@ "use strict";

const fieldMapIndex = meta[methodName].fieldMapIndex;
const gqlQuery = meta[methodName].gqlQuery;
const gqlOperationName = meta[methodName].gqlOperationName;
const gqlVariablesIndex = meta[methodName].gqlVariablesIndex;
let data = {};

@@ -250,2 +253,13 @@ // @Body

}
// @GraphQL
if (gqlQuery) {
data.query = gqlQuery;
if (gqlOperationName) {
data.operationName = gqlOperationName;
}
// @GraphQLVariables
if (gqlVariablesIndex >= 0) {
data.variables = args[gqlVariablesIndex];
}
}
const contentType = headers["content-type"] || "application/json";

@@ -252,0 +266,0 @@ const dataResolverFactory = new dataResolver_1.DataResolverFactory();

@@ -373,1 +373,27 @@ "use strict";

};
/**
* A easy way to send GraphQL query.
* @param query
* @param operationName
* @sample @GraphQL(gqlQuery)
* @constructor
*/
exports.GraphQL = (query, operationName) => {
return (target, methodName) => {
ensureMeta(target, methodName);
target.__meta__[methodName].gqlQuery = query;
target.__meta__[methodName].gqlOperationName = operationName;
};
};
/**
* Adds variables to GraphQL query
* @param target
* @param methodName
* @param paramIndex
* @sample @GraphQLVariables variables: any
* @constructor
*/
exports.GraphQLVariables = (target, methodName, paramIndex) => {
ensureMeta(target, methodName);
target.__meta__[methodName].gqlVariablesIndex = paramIndex;
};

@@ -238,2 +238,19 @@ import { ResponseType as AxiosResponseType, AxiosTransformer, AxiosRequestConfig } from "axios";

export declare const Config: (config: Partial<AxiosRequestConfig>) => (target: any, methodName: string) => void;
/**
* A easy way to send GraphQL query.
* @param query
* @param operationName
* @sample @GraphQL(gqlQuery)
* @constructor
*/
export declare const GraphQL: (query: string, operationName?: string | undefined) => (target: any, methodName: string) => void;
/**
* Adds variables to GraphQL query
* @param target
* @param methodName
* @param paramIndex
* @sample @GraphQLVariables variables: any
* @constructor
*/
export declare const GraphQLVariables: (target: any, methodName: string, paramIndex: number) => void;
export {};

2

package.json
{
"name": "ts-retrofit",
"version": "1.12.0",
"version": "1.13.0",
"description": "A declarative and axios based retrofit implementation for JavaScript and TypeScript.",

@@ -5,0 +5,0 @@ "repository": "https://github.com/nullcc/ts-retrofit",

@@ -6,4 +6,4 @@ # ts-retrofit

| Statements | Branches | Functions | Lines |
| -----------|----------|-----------|-------|
| Statements | Branches | Functions | Lines |
| ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ----------------------------------- |
| ![Statements](#statements# "Make me better!") | ![Branches](#branches# "Make me better!") | ![Functions](#functions# "Make me better!") | ![Lines](#lines# "Make me better!") |

@@ -350,6 +350,3 @@

@GET("/items")
@Queries({
size: 20,
})
async getItems(): Promise<Response<Array<Item>>> { return <Response<Array<Item>>> {} };
async getItems(@Query('size') size: number): Promise<Response<Array<Item>>> { return <Response<Array<Item>>> {} };
}

@@ -549,2 +546,33 @@ ```

### GraphQL and GraphQLVariables
* Position: Method
`GraphQL` decorator declares query for a GraphQL request.
`GraphQLVariables` decorator declares variables for a GraphQL request.
```typescript
const gqlQuery =
`query ($name: String!, $owner: String!) {
viewer {
name
location
}
repository(name: $name, owner: $owner) {
stargazerCount
forkCount
}
}`;
@BasePath("")
export class GraphQLService extends BaseService {
@POST("/graphql")
@GraphQL(gqlQuery, "UserAndRepo")
async graphql1(
@GraphQLVariables variables: any,
): Promise<Response> { return <Response>{} };
}
```
### Decorators Summary

@@ -581,2 +609,4 @@

| Config | @Config | A direct way to set config for a request in axios | Method | @Config({ maxRedirects: 1 }) |
| GraphQL | @GraphQL | Declares query for a GraphQL request. | Method | @GraphQL(gqlQuery, "operationName") |
| GraphQLVariables | @GraphQLVariables | Decorator declares variables for a GraphQL request. | Method | @GraphQLVariables |

@@ -583,0 +613,0 @@ ## Test

@@ -6,5 +6,5 @@ # ts-retrofit

| Statements | Branches | Functions | Lines |
| -----------|----------|-----------|-------|
| ![Statements](https://img.shields.io/badge/Coverage-96.17%25-brightgreen.svg "Make me better!") | ![Branches](https://img.shields.io/badge/Coverage-85.32%25-yellow.svg "Make me better!") | ![Functions](https://img.shields.io/badge/Coverage-88.12%25-yellow.svg "Make me better!") | ![Lines](https://img.shields.io/badge/Coverage-96.17%25-brightgreen.svg "Make me better!") |
| Statements | Branches | Functions | Lines |
| ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ----------------------------------- |
| ![Statements](https://img.shields.io/badge/Coverage-96.34%25-brightgreen.svg "Make me better!") | ![Branches](https://img.shields.io/badge/Coverage-86.09%25-yellow.svg "Make me better!") | ![Functions](https://img.shields.io/badge/Coverage-88.46%25-yellow.svg "Make me better!") | ![Lines](https://img.shields.io/badge/Coverage-96.34%25-brightgreen.svg "Make me better!") |

@@ -350,6 +350,3 @@ > A declarative and [axios](https://github.com/axios/axios) based retrofit implementation for JavaScript and TypeScript.

@GET("/items")
@Queries({
size: 20,
})
async getItems(): Promise<Response<Array<Item>>> { return <Response<Array<Item>>> {} };
async getItems(@Query('size') size: number): Promise<Response<Array<Item>>> { return <Response<Array<Item>>> {} };
}

@@ -549,2 +546,33 @@ ```

### GraphQL and GraphQLVariables
* Position: Method
`GraphQL` decorator declares query for a GraphQL request.
`GraphQLVariables` decorator declares variables for a GraphQL request.
```typescript
const gqlQuery =
`query ($name: String!, $owner: String!) {
viewer {
name
location
}
repository(name: $name, owner: $owner) {
stargazerCount
forkCount
}
}`;
@BasePath("")
export class GraphQLService extends BaseService {
@POST("/graphql")
@GraphQL(gqlQuery, "UserAndRepo")
async graphql1(
@GraphQLVariables variables: any,
): Promise<Response> { return <Response>{} };
}
```
### Decorators Summary

@@ -581,2 +609,4 @@

| Config | @Config | A direct way to set config for a request in axios | Method | @Config({ maxRedirects: 1 }) |
| GraphQL | @GraphQL | Declares query for a GraphQL request. | Method | @GraphQL(gqlQuery, "operationName") |
| GraphQLVariables | @GraphQLVariables | Decorator declares variables for a GraphQL request. | Method | @GraphQLVariables |

@@ -583,0 +613,0 @@ ## Test

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc