## Query depth deprecation

I'm deprecating depth parameter in our graphql query / cache tooling.
They were obsolete since we introduce the possibility to provide
RecordGqlFields

## Refactor combinedFindManyRecordHook

The hook can now take an array of operationSignatures

## Fix tasks issues

Fix optimistic rendering issue. Note that we still haven't handle
optimisticEffect on creation properly
This commit is contained in:
Charles Bochet
2024-04-29 23:33:23 +02:00
committed by GitHub
parent c946572fde
commit 6a14b1c6d6
187 changed files with 958 additions and 1482 deletions

View File

@ -37,21 +37,10 @@ describe('mapFieldMetadataToGraphQLQuery', () => {
lastName
}`);
});
it('should not return relation if depth is < 1', async () => {
const res = mapFieldMetadataToGraphQLQuery({
objectMetadataItems: mockObjectMetadataItems,
depth: 0,
field: personObjectMetadataItem.fields.find(
(field) => field.name === 'company',
)!,
});
expect(formatGQLString(res)).toEqual('');
});
it('should return relation if it matches depth', async () => {
it('should return non relation subFields if relation', async () => {
const res = mapFieldMetadataToGraphQLQuery({
objectMetadataItems: mockObjectMetadataItems,
depth: 1,
field: personObjectMetadataItem.fields.find(
(field) => field.name === 'company',
)!,
@ -83,168 +72,14 @@ accountOwnerId
employees
id
idealCustomerProfile
}`);
});
it('should return relation with all sub relations if it matches depth', async () => {
const res = mapFieldMetadataToGraphQLQuery({
objectMetadataItems: mockObjectMetadataItems,
depth: 2,
field: personObjectMetadataItem.fields.find(
(field) => field.name === 'company',
)!,
});
expect(formatGQLString(res)).toEqual(`company
{
__typename
xLink
{
label
url
}
accountOwner
{
__typename
colorScheme
name
{
firstName
lastName
}
locale
userId
avatarUrl
createdAt
updatedAt
id
}
linkedinLink
{
label
url
}
attachments
{
edges {
node {
__typename
updatedAt
createdAt
name
personId
activityId
companyId
id
authorId
type
fullPath
}
}
}
domainName
opportunities
{
edges {
node {
__typename
personId
pointOfContactId
updatedAt
companyId
probability
closeDate
amount
{
amountMicros
currencyCode
}
id
createdAt
}
}
}
annualRecurringRevenue
{
amountMicros
currencyCode
}
createdAt
address
updatedAt
activityTargets
{
edges {
node {
__typename
updatedAt
createdAt
personId
activityId
companyId
id
}
}
}
favorites
{
edges {
node {
__typename
id
companyId
createdAt
personId
position
workspaceMemberId
updatedAt
}
}
}
people
{
edges {
node {
__typename
xLink
{
label
url
}
id
createdAt
city
email
jobTitle
name
{
firstName
lastName
}
phone
linkedinLink
{
label
url
}
updatedAt
avatarUrl
companyId
}
}
}
name
accountOwnerId
employees
id
idealCustomerProfile
}`);
});
it('should return GraphQL fields based on queryFields', async () => {
it('should return only return relation subFields that are in recordGqlFields', async () => {
const res = mapFieldMetadataToGraphQLQuery({
objectMetadataItems: mockObjectMetadataItems,
depth: 2,
queryFields: {
accountOwner: true,
relationrecordFields: {
accountOwner: { id: true, name: true },
people: true,
xLink: true,
linkedinLink: true,
@ -274,17 +109,11 @@ xLink
accountOwner
{
__typename
colorScheme
name
{
firstName
lastName
}
locale
userId
avatarUrl
createdAt
updatedAt
id
}
linkedinLink

View File

@ -15,209 +15,11 @@ if (!personObjectMetadataItem) {
}
describe('mapObjectMetadataToGraphQLQuery', () => {
it('should return typename if depth < 0', async () => {
it('should query only specified recordGqlFields', async () => {
const res = mapObjectMetadataToGraphQLQuery({
objectMetadataItems: mockObjectMetadataItems,
objectMetadataItem: personObjectMetadataItem,
depth: -1,
});
expect(formatGQLString(res)).toEqual(`{
__typename
}`);
});
it('should return depth 0 if depth = 0', async () => {
const res = mapObjectMetadataToGraphQLQuery({
objectMetadataItems: mockObjectMetadataItems,
objectMetadataItem: personObjectMetadataItem,
depth: 0,
});
expect(formatGQLString(res)).toEqual(`{
__typename
xLink
{
label
url
}
id
createdAt
city
email
jobTitle
name
{
firstName
lastName
}
phone
linkedinLink
{
label
url
}
updatedAt
avatarUrl
companyId
}`);
});
it('should return depth 1 if depth = 1', async () => {
const res = mapObjectMetadataToGraphQLQuery({
objectMetadataItems: mockObjectMetadataItems,
objectMetadataItem: personObjectMetadataItem,
depth: 1,
});
expect(formatGQLString(res)).toEqual(`{
__typename
opportunities
{
edges {
node {
__typename
personId
pointOfContactId
updatedAt
companyId
probability
closeDate
amount
{
amountMicros
currencyCode
}
id
createdAt
}
}
}
xLink
{
label
url
}
id
pointOfContactForOpportunities
{
edges {
node {
__typename
personId
pointOfContactId
updatedAt
companyId
probability
closeDate
amount
{
amountMicros
currencyCode
}
id
createdAt
}
}
}
createdAt
company
{
__typename
xLink
{
label
url
}
linkedinLink
{
label
url
}
domainName
annualRecurringRevenue
{
amountMicros
currencyCode
}
createdAt
address
updatedAt
name
accountOwnerId
employees
id
idealCustomerProfile
}
city
email
activityTargets
{
edges {
node {
__typename
updatedAt
createdAt
personId
activityId
companyId
id
}
}
}
jobTitle
favorites
{
edges {
node {
__typename
id
companyId
createdAt
personId
position
workspaceMemberId
updatedAt
}
}
}
attachments
{
edges {
node {
__typename
updatedAt
createdAt
name
personId
activityId
companyId
id
authorId
type
fullPath
}
}
}
name
{
firstName
lastName
}
phone
linkedinLink
{
label
url
}
updatedAt
avatarUrl
companyId
}`);
});
it('should query only specified queryFields', async () => {
const res = mapObjectMetadataToGraphQLQuery({
objectMetadataItems: mockObjectMetadataItems,
objectMetadataItem: personObjectMetadataItem,
queryFields: {
recordGqlFields: {
company: true,
xLink: true,
id: true,
@ -232,7 +34,6 @@ companyId
avatarUrl: true,
companyId: true,
},
depth: 1,
});
expect(formatGQLString(res)).toEqual(`{
__typename
@ -291,12 +92,11 @@ companyId
}`);
});
it('should load only specified query fields', async () => {
it('should load only specified operation fields nested', async () => {
const res = mapObjectMetadataToGraphQLQuery({
objectMetadataItems: mockObjectMetadataItems,
objectMetadataItem: personObjectMetadataItem,
queryFields: { company: true, id: true, name: true },
depth: 1,
recordGqlFields: { company: { id: true }, id: true, name: true },
});
expect(formatGQLString(res)).toEqual(`{
__typename
@ -304,30 +104,7 @@ id
company
{
__typename
xLink
{
label
url
}
linkedinLink
{
label
url
}
domainName
annualRecurringRevenue
{
amountMicros
currencyCode
}
createdAt
address
updatedAt
name
accountOwnerId
employees
id
idealCustomerProfile
}
name
{

View File

@ -2,113 +2,50 @@ import { shouldFieldBeQueried } from '@/object-metadata/utils/shouldFieldBeQueri
import { FieldMetadataType } from '~/generated-metadata/graphql';
describe('shouldFieldBeQueried', () => {
describe('if field is not relation', () => {
it('should be queried if depth is undefined', () => {
describe('if recordGqlFields is absent, we query all except relations', () => {
it('should be queried if the field is not a relation', () => {
const res = shouldFieldBeQueried({
field: { name: 'fieldName', type: FieldMetadataType.Boolean },
});
expect(res).toBe(true);
});
it('should be queried depth = 0', () => {
it('should not be queried if the field is a relation', () => {
const res = shouldFieldBeQueried({
depth: 0,
field: { name: 'fieldName', type: FieldMetadataType.Boolean },
});
expect(res).toBe(true);
});
it('should be queried depth > 0', () => {
const res = shouldFieldBeQueried({
depth: 1,
field: { name: 'fieldName', type: FieldMetadataType.Boolean },
});
expect(res).toBe(true);
});
it('should NOT be queried depth < 0', () => {
const res = shouldFieldBeQueried({
depth: -1,
field: { name: 'fieldName', type: FieldMetadataType.Boolean },
field: { name: 'fieldName', type: FieldMetadataType.Relation },
});
expect(res).toBe(false);
});
it('should not depends on queryFields', () => {
const res = shouldFieldBeQueried({
depth: 0,
queryFields: {
fieldName: true,
},
field: { name: 'fieldName', type: FieldMetadataType.Boolean },
});
expect(res).toBe(true);
});
});
describe('if field is relation', () => {
it('should be queried if queryFields and depth are undefined', () => {
describe('if recordGqlFields is present, we respect it', () => {
it('should be queried if true', () => {
const res = shouldFieldBeQueried({
recordGqlFields: { fieldName: true },
field: { name: 'fieldName', type: FieldMetadataType.Relation },
});
expect(res).toBe(true);
});
it('should be queried if queryFields is undefined and depth = 1', () => {
it('should be queried if object', () => {
const res = shouldFieldBeQueried({
depth: 1,
recordGqlFields: { fieldName: { subFieldName: false } },
field: { name: 'fieldName', type: FieldMetadataType.Relation },
});
expect(res).toBe(true);
});
it('should be queried if queryFields is undefined and depth > 1', () => {
it('should not be queried if false', () => {
const res = shouldFieldBeQueried({
depth: 2,
field: { name: 'fieldName', type: FieldMetadataType.Relation },
});
expect(res).toBe(true);
});
it('should NOT be queried if queryFields is undefined and depth < 1', () => {
const res = shouldFieldBeQueried({
depth: 0,
recordGqlFields: { fieldName: false },
field: { name: 'fieldName', type: FieldMetadataType.Relation },
});
expect(res).toBe(false);
});
it('should be queried if queryFields is matching and depth > 1', () => {
it('should not be queried if absent', () => {
const res = shouldFieldBeQueried({
depth: 1,
queryFields: { fieldName: true },
field: { name: 'fieldName', type: FieldMetadataType.Relation },
});
expect(res).toBe(true);
});
it('should NOT be queried if queryFields is matching and depth < 1', () => {
const res = shouldFieldBeQueried({
depth: 0,
queryFields: { fieldName: true },
field: { name: 'fieldName', type: FieldMetadataType.Relation },
});
expect(res).toBe(false);
});
it('should NOT be queried if queryFields is not matching (falsy) and depth < 1', () => {
const res = shouldFieldBeQueried({
depth: 1,
queryFields: { fieldName: false },
field: { name: 'fieldName', type: FieldMetadataType.Relation },
});
expect(res).toBe(false);
});
it('should NOT be queried if queryFields is not matching and depth < 1', () => {
const res = shouldFieldBeQueried({
depth: 0,
queryFields: { anotherFieldName: true },
recordGqlFields: { otherFieldName: false },
field: { name: 'fieldName', type: FieldMetadataType.Relation },
});
expect(res).toBe(false);