add types for most of graphql

This commit is contained in:
Elliot DeNolf
2020-11-24 20:03:41 -05:00
parent c9cb1ea05c
commit e36be704a5
18 changed files with 137 additions and 63 deletions

View File

@@ -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';

View File

@@ -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;