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,
});

Configurable 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

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 Nate Wienert