add types for most of graphql
This commit is contained in:
@@ -83,19 +83,19 @@ export type SelectManyField = SelectField & {
|
||||
hasMany: true;
|
||||
}
|
||||
|
||||
type RelationShipSingleField = FieldBase & {
|
||||
export type RelationshipSingleField = FieldBase & {
|
||||
type: 'relationship';
|
||||
relationTo: string;
|
||||
hasMany?: false;
|
||||
}
|
||||
|
||||
type RelationShipManyField = FieldBase & {
|
||||
export type RelationshipManyField = FieldBase & {
|
||||
type: 'relationship';
|
||||
relationTo: string[] | string;
|
||||
relationTo: string[];
|
||||
hasMany: true;
|
||||
}
|
||||
|
||||
export type RelationshipField = RelationShipSingleField | RelationShipManyField;
|
||||
export type RelationshipField = RelationshipSingleField | RelationshipManyField;
|
||||
|
||||
type RichTextElements = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'blockquote' | 'ul' | 'ol' | 'link';
|
||||
type RichTextLeaves = 'bold' | 'italic' | 'underline' | 'strikethrough';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import executeAccess from '../auth/executeAccess';
|
||||
import { OperationArguments } from '../types';
|
||||
import { RelationshipField } from './config/types';
|
||||
|
||||
const populate = async ({
|
||||
depth,
|
||||
@@ -15,7 +16,8 @@ const populate = async ({
|
||||
}: OperationArguments) => {
|
||||
const dataToUpdate = dataReference;
|
||||
|
||||
const relation = Array.isArray(field.relationTo) ? data.relationTo : field.relationTo;
|
||||
const fieldAsRelationship = field as RelationshipField;
|
||||
const relation = Array.isArray(fieldAsRelationship.relationTo) ? data.relationTo : fieldAsRelationship.relationTo;
|
||||
const relatedCollection = payload.collections[relation];
|
||||
|
||||
if (relatedCollection) {
|
||||
@@ -24,7 +26,7 @@ const populate = async ({
|
||||
let populatedRelationship = null;
|
||||
|
||||
if (accessResult && (depth && currentDepth <= depth)) {
|
||||
let idString = Array.isArray(field.relationTo) ? data.value : data;
|
||||
let idString = Array.isArray(fieldAsRelationship.relationTo) ? data.value : data;
|
||||
|
||||
if (typeof idString !== 'string') {
|
||||
idString = idString.toString();
|
||||
@@ -45,12 +47,12 @@ const populate = async ({
|
||||
// If populatedRelationship comes back, update value
|
||||
if (!accessResult || populatedRelationship) {
|
||||
if (typeof index === 'number') {
|
||||
if (Array.isArray(field.relationTo)) {
|
||||
if (Array.isArray(fieldAsRelationship.relationTo)) {
|
||||
dataToUpdate[field.name][index].value = populatedRelationship;
|
||||
} else {
|
||||
dataToUpdate[field.name][index] = populatedRelationship;
|
||||
}
|
||||
} else if (Array.isArray(field.relationTo)) {
|
||||
} else if (Array.isArray(fieldAsRelationship.relationTo)) {
|
||||
dataToUpdate[field.name].value = populatedRelationship;
|
||||
} else {
|
||||
dataToUpdate[field.name] = populatedRelationship;
|
||||
|
||||
Reference in New Issue
Block a user