You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

graph-api-client

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graph-api-client

JS Library created to simplify using of GraphQL by using a defined structure for queries and mutations, instead of passing raw strings to the API handler

1.2.3
latest
Source
npm
Version published
Maintainers
1
Created
Source

Graph API Client

JS Library created to simplify using of GraphQL by using a defined structure for queries and mutations, instead of passing raw strings to the API handler

Just create an instance of the GraphAPIClient object and it will take care of the rest

class GraphAPIClient {
    constructor(
        axiosRequestConfig: AxiosRequestConfig = {}, 
        clientConfig: IGraphClientConfig = defaultClientConfig
    ) {
        this.axios = axios.create(axiosRequestConfig);
        this.config = Object.assign({}, defaultClientConfig, clientConfig);
    }
}

the axiosRequestConfig parameter sets default parameters for the internal axios instance, while clientConfig sets the default API request payload keys, by default {query, variables}

Requests sending

Just call client.query or client.mutation to enjoy the magic

Query method
public query<T>(path: string = '/graphql', requests: GraphQLRequest[], config: AxiosRequestConfig = {}): Promise<T> {
    const body = this.collectRequestBody('query', requests);
    return this.post<T>(path, body, config);
}
Mutate method
public mutate<T>(path: string = '/graphql', requests: GraphQLRequest[], config: AxiosRequestConfig = {}): Promise<T> {
    const body = this.collectRequestBody('mutation', requests);
    return this.post<T>(path, body, config);
}

Requests Generation

Both GraphQL queries and mutations are being generated by the graphql-request-generator library, which I made.
To read about request generation check the repo's README

Keywords

graphql

FAQs

Package last updated on 09 Apr 2020

Did you know?

Socket

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.

Install

Related posts