【问题标题】:Adapter type "mongoose" does not support field type "CloudinaryImage"适配器类型“mongoose”不支持字段类型“CloudinaryImage”
【发布时间】:2021-09-26 20:32:09
【问题描述】:

当我运行项目时,出现这样的错误:初始化 Keystone 时出错
错误:适配器类型“mongoose”不支持字段类型“CloudinaryImage”。我该如何解决?

【问题讨论】:

  • 能否分享您的 Keystone 配置以及与此错误相关的代码段?这可能有助于找出罪魁祸首
  • 我做到了。你可以看看下面

标签: mongoose cloudinary


【解决方案1】:
import { createAuth } from '@keystone-next/auth';
import { config, createSchema } from '@keystone-next/keystone/schema';
import {
    withItemData,
    statelessSessions,
} from '@keystone-next/keystone/session';
import { KeystoneContext } from '@keystone-next/types';
import { permissionsList } from './schemas/fields';
import { Role } from './schemas/Role';
import { Listing } from './schemas/Listing';
import { ListingImage } from './schemas/ListingImage';
import { Profile } from './schemas/Profile';
import { User } from './schemas/User';
import { PersonalInfo } from './schemas/PersonalInfo';
import { TaskerProfile } from './schemas/TaskerProfile';
import { WorkPlace } from './schemas/WorkPlace';
import { Calendar } from './schemas/Calendar';
import { ClosingMessage } from './schemas/ClosingMessages';
import { OngoingClosingMessage } from './schemas/OngoingClosingMessages';
import { PromoteYourself } from './schemas/PromoteYourself';
import { Payment } from './schemas/Payments';
import { Support } from './schemas/Support';
import 'dotenv/config';
import { extendGraphqlSchema } from './mutations';

const databaseURL = process.env.DATABASE_URL;

const sessionConfig = {
    maxAge: 60 * 60 * 24 * 360,
    secret: process.env.COOKIE_SECRET,
};

const { withAuth } = createAuth({
    listKey: 'User',
    identityField: 'email',
    secretField: 'password',
    initFirstItem: {
        fields: ['name', 'email', 'password'],
        // TODO: Add in inital roles here
    },
    // passwordResetLink: {
    //     async sendToken(args) {
    //         // send the email
    //         await sendPasswordResetEmail(args.token, args.identity);
    //     },
    // },
});

export default withAuth(
    config({
        server: {
            cors: {
                origin: true, // TODO: add only allowed URLs -> [process.env.CUSTOMER_PORTAL,...]
                credentials: true,
            },
            port: process.env.SERVER_PORT,
        },
        db: {
            adapter: 'mongoose',
            url: databaseURL,
            // eslint-disable-next-line @typescript-eslint/require-await
            async onConnect(keystone) {
                console.log('Connected to the database!');
                // if (process.argv.includes('--seed-data')) {
                //    await insertSeedData(keystone);
                // }
            },
        },
        lists: createSchema({
            // Schema items go in here
            User,
            Role,
            Listing,
            ListingImage,
            Profile,
            PersonalInfo,
            Calendar,
            ClosingMessage,
            OngoingClosingMessage,
            PromoteYourself,
            Payment,
            Support,
            WorkPlace,
            TaskerProfile
        }),
        extendGraphqlSchema,
        ui: {
            // Show the UI only for people who pass this test
            isAccessAllowed: ({ session }) =>
                // console.log(session);
                !!session?.data,
        },
        session: withItemData(statelessSessions(sessionConfig), {
            // GraphQL Query
            User: `id name email role { ${permissionsList.join(' ')} }`,
        }),
        images: {
            upload: 'local',
            local: {
              storagePath: 'public/images',
              baseUrl: '/images',
            },
        },
    })
);

【讨论】:

    【解决方案2】:
    import 'dotenv/config';
    import { relationship, text } from '@keystone-next/fields';
    import { list } from '@keystone-next/keystone/schema';
    import { cloudinaryImage } from '@keystone-next/cloudinary';
    import { isSignedIn, permissions } from '../access';
    
    export const cloudinary = {
        cloudName: process.env.CLOUDINARY_CLOUD_NAME,
        apiKey: process.env.CLOUDINARY_KEY,
        apiSecret: process.env.CLOUDINARY_SECRET,
        folder: 'abdul',
    };
    
    export const ListingImage = list({
        access: {
            create: () => true,
            read: () => true, // this is required to make the entity public
            update: () => true,
            delete: () => true,
        },
        fields: {
            image: cloudinaryImage({
                cloudinary,
                label: 'Source',
            }),
            altText: text(),
            listing: relationship({
                ref: 'Listing.photo',
                ui: {
                    displayMode: 'select'
                }
            }),
        },
        ui: {
            listView: {
                initialColumns: ['image', 'altText', 'listing'],
            },
        },
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-16
      • 2016-10-08
      • 2019-04-21
      • 1970-01-01
      • 2017-02-10
      相关资源
      最近更新 更多