3.0.0-alpha.5 • Published 10 months ago
@afosto/graphql-client v3.0.0-alpha.5
Installation
# Install with Yarn
yarn add @afosto/graphql-client graphql
# Install with NPM
npm install @afosto/graphql-client graphql
Basic usage
import GraphQLClient, { gql } from '@afosto/graphql-client';
// For authentication
GraphQLClient.setAuthorizationHeader('AUTH_TOKEN');
// Your graphQL query and variables.
const query = gql``;
const variables = {};
// Request
await GraphQLClient.request(query, variables);
Custom configuration
If you would like to use the GraphQLClient with other configuration than the default configuration.
Option | Description | Default | |
---|---|---|---|
url | The base url for the client. | https://afosto.app/graphql | |
convertResponseToCamelCase | Whether to convert the response data to camel case. | true | |
convertVariablesToSnakeCase | Whether to convert the variables to snake case. | true | |
excludeConversionKeys | Set the keys that should be excluded from being converted to camel case and snake case. | [] | |
stopPaths | Exclude children at the given object paths in dot-notation from being converted to camel case. Note: Is not yet implemented for snake case conversion | [] |
import { GraphQLClient } from '@afosto/graphql-client';
const client = new GraphQLClient({
// Your configuration.
});
// For authentication
client.setAuthorizationHeader('AUTH_TOKEN');
// Your graphQL query and variables.
const query = gql``;
const variables = {};
// Request
await client.request(query, variables);
Default response transformation
By default the Afosto GraphQLClient will transform the response keys to camel case and the variable keys to snake case. If you would like to change these settings, you can do the following:
Default client
GraphQLClient.setConvertResponseToCamelCase(false);
GraphQLClient.setConvertVariablesToSnakeCase(false);
Custom client
import { GraphQLClient } from '@afosto/graphql-client';
const client = new GraphQLClient({
// Your configuration.
convertResponseToCamelCase: false,
convertVariablesToSnakeCase: false,
});
// Or after client initialization
client.setConvertResponseToCamelCase(false);
client.setConvertVariablesToSnakeCase(false);
Custom response transformation
If you would like to alter the response data yourself, you can use the following:
await GraphQLClient.request(query, variables, {
transformResponse: [
response => {
// Alter and return your new response data.
return response;
},
],
});
Compatibility
- Node >= 18
3.0.0-alpha.1
10 months ago
3.0.0-alpha.3
10 months ago
3.0.0-alpha.2
10 months ago
3.0.0-alpha.5
10 months ago
3.0.0-alpha.4
10 months ago
2.1.5
1 year ago
2.1.2
1 year ago
2.0.3
1 year ago
2.1.1
1 year ago
2.0.2
1 year ago
2.1.4
1 year ago
2.1.3
1 year ago
2.1.0
1 year ago
2.0.1
2 years ago
2.0.0
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago