GraphQLError: Syntax Error: Expected Name, found ":"

GraphQLError: Syntax Error: Expected Name, found ":"

我正在尝试将 Prisma 与 Apollo Server 一起使用 我一直收到这个错误

GraphQLError: Syntax Error: Expected Name, found ":"

这是 index.ts 文件

import { PrismaClient } from '@prisma/client';
import { ApolloServer } from 'apollo-server';
import { typeDefs } from './schema/schema';
import { Query } from './resolvers/Query';
import { Mutation } from './resolvers/Mutation';

const prisma = new PrismaClient();
const server = new ApolloServer({
  typeDefs,
  resolvers: {
    Query,
    Mutation,
  },
  context: {
    prisma,
  },
});

server.listen().then(({ url }: any) => {
  console.log(`Server is running on ${url}`);
});

这是 schema.ts 文件

const { gql } = require('apollo-server');

export const typeDefs = gql`
  type Query {
    getProducts: [Product!]!
  }

  type Mutation {
    addProduct(input: addProductInput): Boolean!
  }

  type Product {
    name: String!
    price: Float!
    description: : String!
  }

  input addProductInput {
    name: String!
    price: Float!
    description: : String!
  }
`;

这是解析器文件夹中的 Query.ts 文件

export const Query = {
  getProducts: async (parent: any, args: any, { prisma }: any) => {
    return await prisma.products.findMany();
  },
};

这是解析器文件夹中的 Query.ts 文件

export const Mutation = {
  addProduct: async (parent: any, { input }: any, { prisma }: any) => {
    const productData = {
      name: input.name,
      price: input.price,
      description: input.description,
    };

    await prisma.products.create({
      data: productData,
    });

    return true;
  },
};

最后这是 schema.prisma 文件中的产品模型

model Product {
  @@map(name: "products")
  id Int @id @default(autoincrement())
  name String
  price Float
  description String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

我做了一些研究,我得到的只是可能是缺少括号或大括号,但我多次检查我的代码并没有发现任何错误。

在架构定义中,密切关注 Product 类型和 addProductInput:

  type Product {
    name: String!
    price: Float!
    description: : String!
  }

  input addProductInput {
    name: String!
    price: Float!
    description: : String!
  }
`;

您确定描述字段应该有两个冒号吗?我认为他们不应该有中间那个,就像description: String!