Core Configuration#
The Core Client has some configurations you can set manually:
createClient<GeneratedSchema, SchemaObjectTypesNames, SchemaObjectTypes>({
// Required configuration
schema: generatedSchema,
scalarsEnumsHash,
queryFetcher,
// Optional configurable options
catchSelectionsTimeMS: 10,
retry: true,
normalization: true,
subscriptionsClient,
});
ClientOptions#
Name | Type | Default Value | Description |
---|---|---|---|
catchSelectionsTimeMS | number | 10 | Amount of time in milliseconds for the scheduler to wait for grouping data selections together |
retry | RetryOptions | true | Retry on error behavior |
normalization | boolean or NormalizationOptions | true | Enable, disable and configure Normalization |
subscriptionsClient | SubscriptionsClient | undefined | Subscriptions client |
depthLimit | number | 15 | Set the maximum depth limit, needed to prevent possible infinite recursion. After the specified depth is reached, the proxy creation is stopped returning null |
RetryOptions#
By default GQty has a retry policy of 3
max retries, with a delay of a standard back-off delay (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000)
ms.
You can customize it this way:
retry = false
to disable it.retry = 6
it will retry failing requests6
times, with the standard back-off delay.retry = true
to use the default3
max retries, with a delay of standard, a back-off delay.{ maxRetries: 6, retryDelay: 2000 }
for6
max retries, with flat 2000ms of delay per retry.{ retryDelay: function customRetryDelay(attemptIndex) { ... } }
for3
max retries with custom back-off delay, and so on...
Normalization#
GQty has support for normalization, which helps to reduce data redundancy and improve data integrity across all the cache.
It is enabled
by default, but you can disable it, which will disable the need of automatically fetching __typename
and id's
and all the computing logic needed to support it.
createClient<GeneratedSchema, SchemaObjectTypes, SchemaObjectTypesNames>({
// ...
normalization: false,
});
But often enough, it's very useful, and keep in mind that Normalization
in GQty is highly customizable:
Identifier#
You can specify a custom object identifier function.
It gives an incoming object with it's __typename
and it should return:
- A string if successfully identified
- 'null' if it shouldn't be normalized
- Or 'undefined', to fallback to either default or custom
keyFields
createClient<GeneratedSchema, SchemaObjectTypes, SchemaObjectTypesNames>({
// ...
normalization: {
identifier(obj) {
switch (obj.__typename) {
case 'User': {
if (obj.email) {
return `${obj.__typename}${obj.email}`;
}
return null;
}
default: {
return;
}
}
},
},
});
keyFields#
Auto-fetch & object identifier customization.
Keep in mind that GQty already checks your schema and looks for the fields id or __id and it add thems automatically.
Set custom id's of any object type in your schema.
IMPORTANT: Please make sure to only put Scalars
without any variable needed as keyFields
createClient<GeneratedSchema, SchemaObjectTypes, SchemaObjectTypesNames>({
// ...
normalization: {
keyFields: {
User: ['email'],
},
},
});