Skip to main content

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#

NameTypeDefault ValueDescription
catchSelectionsTimeMSnumber10Amount of time in milliseconds for the scheduler to wait for grouping data selections together
retryRetryOptionstrueRetry on error behavior
normalizationboolean or NormalizationOptionstrueEnable, disable and configure Normalization
subscriptionsClientSubscriptionsClientundefinedSubscriptions client

RetryOptions#

By default GQless 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 requests 6 times, with the standard back-off delay.
  • retry = true to use the default 3 max retries, with a delay of standard, a back-off delay.
  • { maxRetries: 6, retryDelay: 2000 } for 6 max retries, with flat 2000ms of delay per retry.
  • { retryDelay: function customRetryDelay(attemptIndex) { ... } } for 3 max retries with custom back-off delay, and so on...

Normalization#

GQless 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 GQless 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 GQless 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'],
},
},
});
Last updated on by github-actions[bot]