UnhandledPromiseRejectionWarning:错误:类型查询必须定义一个或多个字段 [英] UnhandledPromiseRejectionWarning: Error: Type Query must define one or more fields

查看:190
本文介绍了UnhandledPromiseRejectionWarning:错误:类型查询必须定义一个或多个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

import { gql } from "apollo-server-express";

export const typeDefs = gql`
  type Query 
  type Mutation {
    id: ID!
    text: String!
  }
`;

我只有突变,不需要Query.i报错

I only have mutations, I don’t need Query.i get error

UnhandledPromiseRejectionWarning:错误:类型查询必须定义一个或多个字段.

UnhandledPromiseRejectionWarning: Error: Type Query must define one or more fields.

如何声明一个空查询?

推荐答案

来自规范:

模式定义了它支持的每种操作的初始根操作类型:查询,变异和订阅;这确定了这些操作开始在类型系统中的位置.

A schema defines the initial root operation type for each kind of operation it supports: query, mutation, and subscription; this determines the place in the type system where those operations begin.

必须提供查询根操作类型,并且必须是对象类型.

突变根操作类型是可选的;如果未提供,则该服务不支持突变.如果提供,则必须为对象类型.

The mutation root operation type is optional; if it is not provided, the service does not support mutations. If it is provided, it must be an Object type.

此外:

对象类型必须定义一个或多个字段.

An Object type must define one or more fields.

因此必须提供查询根操作类型 ,它必须是一个对象类型,因此,必须包含在至少一个字段.

So a query root operation type must be provided, it must be an Object type and, as a result, it must include at least one field.

您需要为查询提供至少一个 field ,即使它从未使用过并且总是返回null.

You'll need to provide at least one field for Query, even if it's never used and always just returns null.

这篇关于UnhandledPromiseRejectionWarning:错误:类型查询必须定义一个或多个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆