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

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

问题描述

这是我的代码

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

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

我只有突变,我不需要查询.我得到错误

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.

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

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

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.

您至少需要为 Query 提供一个 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天全站免登陆