4655 batch endpoints on the rest api (#5411)
- add POST rest/batch/<OBJECT> endpoint - rearrange rest api code with Twenty quality standard - unify REST API error format - Added PATCH verb to update objects - In openapi schema, we replaced PUT with PATCH verb to comply with REST standard - fix openApi schema to match the REST api ### Batch Create  ### Replace PUT by PATCH in open Api  ### Error format unification   
This commit is contained in:
@ -0,0 +1,53 @@
|
||||
import { cleanGraphQLResponse } from 'src/engine/api/rest/utils/clean-graphql-response.utils';
|
||||
|
||||
describe('cleanGraphQLResponse', () => {
|
||||
it('should remove edges/node from results', () => {
|
||||
const data = {
|
||||
companies: {
|
||||
edges: [
|
||||
{
|
||||
node: { id: 'id', createdAt: '2023-01-01' },
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
const expectedResult = {
|
||||
companies: [{ id: 'id', createdAt: '2023-01-01' }],
|
||||
};
|
||||
|
||||
expect(cleanGraphQLResponse(data)).toEqual(expectedResult);
|
||||
});
|
||||
it('should remove nested edges/node from results', () => {
|
||||
const data = {
|
||||
companies: {
|
||||
edges: [
|
||||
{
|
||||
node: {
|
||||
id: 'id',
|
||||
createdAt: '2023-01-01',
|
||||
people: {
|
||||
edges: [{ node: { id: 'id1' } }, { node: { id: 'id2' } }],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
const expectedResult = {
|
||||
companies: [
|
||||
{
|
||||
id: 'id',
|
||||
createdAt: '2023-01-01',
|
||||
people: [{ id: 'id1' }, { id: 'id2' }],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
expect(cleanGraphQLResponse(data)).toEqual(expectedResult);
|
||||
});
|
||||
it('should not format when no list returned', () => {
|
||||
const data = { company: { id: 'id' } };
|
||||
|
||||
expect(cleanGraphQLResponse(data)).toEqual(data);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,22 @@
|
||||
// https://gist.github.com/ManUtopiK/469aec75b655d6a4d912aeb3b75af3c9
|
||||
export const cleanGraphQLResponse = (input: any) => {
|
||||
if (!input) return null;
|
||||
const output = {};
|
||||
const isObject = (obj: any) => {
|
||||
return obj !== null && typeof obj === 'object' && !Array.isArray(obj);
|
||||
};
|
||||
|
||||
Object.keys(input).forEach((key) => {
|
||||
if (input[key] && input[key].edges) {
|
||||
output[key] = input[key].edges.map((edge) =>
|
||||
cleanGraphQLResponse(edge.node),
|
||||
);
|
||||
} else if (isObject(input[key])) {
|
||||
output[key] = cleanGraphQLResponse(input[key]);
|
||||
} else if (key !== '__typename') {
|
||||
output[key] = input[key];
|
||||
}
|
||||
});
|
||||
|
||||
return output;
|
||||
};
|
||||
Reference in New Issue
Block a user