1.2.3 • Published 4 years ago

graph-api-client v1.2.3

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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

1.2.3

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.0.13-beta

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago