Add count fn support to gql (#12684)

This commit is contained in:
Rijk van Zanten
2022-04-11 14:58:32 -04:00
committed by GitHub
parent 029a66ef31
commit a117e5b65f

View File

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