mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add count fn support to gql (#12684)
This commit is contained in:
@@ -358,6 +358,15 @@ export class GraphQLService {
|
||||
function getTypes(action: 'read' | 'create' | 'update' | 'delete') {
|
||||
const CollectionTypes: Record<string, ObjectTypeComposer> = {};
|
||||
|
||||
const CountFunctions = schemaComposer.createObjectTC({
|
||||
name: 'count_functions',
|
||||
fields: {
|
||||
count: {
|
||||
type: GraphQLInt,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const DateFunctions = schemaComposer.createObjectTC({
|
||||
name: 'date_functions',
|
||||
fields: {
|
||||
@@ -460,6 +469,16 @@ export class GraphQLService {
|
||||
};
|
||||
}
|
||||
|
||||
if (field.type === 'json' || field.type === 'alias') {
|
||||
acc[`${field.field}_func`] = {
|
||||
type: CountFunctions,
|
||||
resolve: (obj: Record<string, any>) => {
|
||||
const funcFields = Object.keys(CountFunctions.getFields()).map((key) => `${field.field}_${key}`);
|
||||
return mapKeys(pick(obj, funcFields), (_value, key) => key.substring(field.field.length + 1));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {} as ObjectTypeComposerFieldConfigMapDefinition<any, any>),
|
||||
});
|
||||
@@ -694,6 +713,15 @@ export class GraphQLService {
|
||||
},
|
||||
});
|
||||
|
||||
const CountFunctionFilterOperators = schemaComposer.createInputTC({
|
||||
name: 'count_function_filter_operators',
|
||||
fields: {
|
||||
count: {
|
||||
type: NumberFilterOperators,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const DateFunctionFilterOperators = schemaComposer.createInputTC({
|
||||
name: 'date_function_filter_operators',
|
||||
fields: {
|
||||
@@ -787,6 +815,12 @@ export class GraphQLService {
|
||||
};
|
||||
}
|
||||
|
||||
if (field.type === 'json' || field.type === 'alias') {
|
||||
acc[`${field.field}_func`] = {
|
||||
type: CountFunctionFilterOperators,
|
||||
};
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {} as InputTypeComposerFieldConfigMapDefinition),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user