UnhandledPromiseRejectionWarning: Error: Type Query must define one or more fields
UnhandledPromiseRejectionWarning: Error: Type Query must define one or more fields
这是我的代码
import { gql } from "apollo-server-express";
export const typeDefs = gql`
type Query
type Mutation {
id: ID!
text: String!
}
`;
我只有突变,不需要Query.i得到错误
UnhandledPromiseRejectionWarning: Error: Type Query must define one or more fields.
如何声明空查询?
来自spec:
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 query root operation type must be provided and must be an Object type.
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.
因此必须提供查询根操作类型,它必须是对象类型,因此,它必须包括至少一个字段。
您需要为查询提供至少一个 field
,即使它从未使用过并且始终只是 returns null。
这是我的代码
import { gql } from "apollo-server-express";
export const typeDefs = gql`
type Query
type Mutation {
id: ID!
text: String!
}
`;
我只有突变,不需要Query.i得到错误
UnhandledPromiseRejectionWarning: Error: Type Query must define one or more fields.
如何声明空查询?
来自spec:
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 query root operation type must be provided and must be an Object type.
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.
因此必须提供查询根操作类型,它必须是对象类型,因此,它必须包括至少一个字段。
您需要为查询提供至少一个 field
,即使它从未使用过并且始终只是 returns null。