Refacto rest api, fix graphl playground, improve analytics (#5844)
- Improve the rest api by introducing startingAfter/endingBefore (we previously had lastCursor), and moving pageInfo/totalCount outside of the data object. - Fix broken GraphQL playground on website - Improve analytics by sending server url
This commit is contained in:
@ -2,11 +2,12 @@ import { OrderByDirection } from 'src/engine/api/graphql/workspace-query-builder
|
||||
|
||||
import {
|
||||
computeDepthParameters,
|
||||
computeEndingBeforeParameters,
|
||||
computeFilterParameters,
|
||||
computeIdPathParameter,
|
||||
computeLastCursorParameters,
|
||||
computeLimitParameters,
|
||||
computeOrderByParameters,
|
||||
computeStartingAfterParameters,
|
||||
} from 'src/engine/core-modules/open-api/utils/parameters.utils';
|
||||
import { DEFAULT_ORDER_DIRECTION } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/order-by-input.factory';
|
||||
import { FilterComparators } from 'src/engine/api/rest/rest-api-core-query-builder/factories/input-factories/filter-utils/parse-base-filter.utils';
|
||||
@ -106,13 +107,27 @@ describe('computeParameters', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('computeLastCursor', () => {
|
||||
it('should compute last cursor', () => {
|
||||
expect(computeLastCursorParameters()).toEqual({
|
||||
name: 'last_cursor',
|
||||
describe('computeStartingAfter', () => {
|
||||
it('should compute starting after', () => {
|
||||
expect(computeStartingAfterParameters()).toEqual({
|
||||
name: 'starting_after',
|
||||
in: 'query',
|
||||
description:
|
||||
'Returns objects starting from a specific cursor. You can find cursors in **startCursor** and **endCursor** in **pageInfo** in response data',
|
||||
'Returns objects starting after a specific cursor. You can find cursors in **startCursor** and **endCursor** in **pageInfo** in response data',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('computeEndingBefore', () => {
|
||||
it('should compute ending_before', () => {
|
||||
expect(computeEndingBeforeParameters()).toEqual({
|
||||
name: 'ending_before',
|
||||
in: 'query',
|
||||
description:
|
||||
'Returns objects ending before a specific cursor. You can find cursors in **startCursor** and **endCursor** in **pageInfo** in response data',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
|
||||
@ -5,11 +5,12 @@ import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/fi
|
||||
import { capitalize } from 'src/utils/capitalize';
|
||||
import {
|
||||
computeDepthParameters,
|
||||
computeEndingBeforeParameters,
|
||||
computeFilterParameters,
|
||||
computeIdPathParameter,
|
||||
computeLastCursorParameters,
|
||||
computeLimitParameters,
|
||||
computeOrderByParameters,
|
||||
computeStartingAfterParameters,
|
||||
} from 'src/engine/core-modules/open-api/utils/parameters.utils';
|
||||
import { compositeTypeDefintions } from 'src/engine/metadata-modules/field-metadata/composite-types';
|
||||
|
||||
@ -223,7 +224,8 @@ export const computeParameterComponents = (): Record<
|
||||
> => {
|
||||
return {
|
||||
idPath: computeIdPathParameter(),
|
||||
lastCursor: computeLastCursorParameters(),
|
||||
startingAfter: computeStartingAfterParameters(),
|
||||
endingBefore: computeEndingBeforeParameters(),
|
||||
filter: computeFilterParameters(),
|
||||
depth: computeDepthParameters(),
|
||||
orderBy: computeOrderByParameters(),
|
||||
|
||||
@ -95,18 +95,33 @@ export const computeFilterParameters = (): OpenAPIV3_1.ParameterObject => {
|
||||
};
|
||||
};
|
||||
|
||||
export const computeLastCursorParameters = (): OpenAPIV3_1.ParameterObject => {
|
||||
return {
|
||||
name: 'last_cursor',
|
||||
in: 'query',
|
||||
description:
|
||||
'Returns objects starting from a specific cursor. You can find cursors in **startCursor** and **endCursor** in **pageInfo** in response data',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
export const computeStartingAfterParameters =
|
||||
(): OpenAPIV3_1.ParameterObject => {
|
||||
return {
|
||||
name: 'starting_after',
|
||||
in: 'query',
|
||||
description:
|
||||
'Returns objects starting after a specific cursor. You can find cursors in **startCursor** and **endCursor** in **pageInfo** in response data',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const computeEndingBeforeParameters =
|
||||
(): OpenAPIV3_1.ParameterObject => {
|
||||
return {
|
||||
name: 'ending_before',
|
||||
in: 'query',
|
||||
description:
|
||||
'Returns objects ending before a specific cursor. You can find cursors in **startCursor** and **endCursor** in **pageInfo** in response data',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export const computeIdPathParameter = (): OpenAPIV3_1.ParameterObject => {
|
||||
return {
|
||||
|
||||
@ -42,14 +42,15 @@ export const computeManyResultPath = (
|
||||
get: {
|
||||
tags: [item.namePlural],
|
||||
summary: `Find Many ${item.namePlural}`,
|
||||
description: `**order_by**, **filter**, **limit**, **depth** or **last_cursor** can be provided to request your **${item.namePlural}**`,
|
||||
description: `**order_by**, **filter**, **limit**, **depth**, **starting_after** or **ending_before** can be provided to request your **${item.namePlural}**`,
|
||||
operationId: `findMany${capitalize(item.namePlural)}`,
|
||||
parameters: [
|
||||
{ $ref: '#/components/parameters/orderBy' },
|
||||
{ $ref: '#/components/parameters/filter' },
|
||||
{ $ref: '#/components/parameters/limit' },
|
||||
{ $ref: '#/components/parameters/depth' },
|
||||
{ $ref: '#/components/parameters/lastCursor' },
|
||||
{ $ref: '#/components/parameters/startingAfter' },
|
||||
{ $ref: '#/components/parameters/endingBefore' },
|
||||
],
|
||||
responses: {
|
||||
'200': getFindManyResponse200(item),
|
||||
|
||||
@ -22,19 +22,19 @@ export const getFindManyResponse200 = (
|
||||
)} with Relations`,
|
||||
},
|
||||
},
|
||||
pageInfo: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
hasNextPage: { type: 'boolean' },
|
||||
startCursor: { type: 'string' },
|
||||
endCursor: { type: 'string' },
|
||||
},
|
||||
},
|
||||
totalCount: {
|
||||
type: 'integer',
|
||||
},
|
||||
},
|
||||
},
|
||||
pageInfo: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
hasNextPage: { type: 'boolean' },
|
||||
startCursor: { type: 'string' },
|
||||
endCursor: { type: 'string' },
|
||||
},
|
||||
},
|
||||
totalCount: {
|
||||
type: 'integer',
|
||||
},
|
||||
},
|
||||
example: {
|
||||
data: {
|
||||
@ -44,6 +44,12 @@ export const getFindManyResponse200 = (
|
||||
'...',
|
||||
],
|
||||
},
|
||||
pageInfo: {
|
||||
hasNextPage: true,
|
||||
startCursor: '56f411fb-0900-4ffb-b942-d7e8d6709eff',
|
||||
endCursor: '93adf3c6-6cf7-4a86-adcd-75f77857ba67',
|
||||
},
|
||||
totalCount: 132,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user