全局配置
这是 GraphQL 库版本 7 的文档。有关长期支持 (LTS) 版本 5,请参阅 GraphQL 库版本 5 LTS。 |
通过 schema 配置,可以全局禁用特定类型的操作。要单独设置操作,请参阅 类型配置。
例如,如果您想**一次性禁用所有顶层聚合操作**,Neo4j GraphQL 库通过使用 @query
的 schema 扩展提供了此选项
type Movie @node {
title: String
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN)
}
type Actor @node {
name: String
movies: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT)
}
extend schema @query(read: true, aggregate: false)
此配置会禁用 Movie
和 Actor
类型的所有顶层聚合操作,但仍允许读取操作。
type Query {
moviesConnection(first: Int, after: String, where: MovieWhere, sort: [MovieSort!]): MoviesConnection!
movies(where: MovieWhere, limit: Int, offset: Int, sort: [MovieSort!]): [Movie!]!
actorsConnection(first: Int, after: String, where: ActorWhere, sort: [ActorSort!]): ActorsConnection!
actors(where: ActorWhere, limit: Int, offset: Int, sort: [ActorSort!]): [Actor!]!
}
type MoviesConnection {
edges: [MovieEdge!]!
totalCount: Int!
pageInfo: PageInfo!
}
type ActorsConnection {
edges: [ActorEdge!]!
totalCount: Int!
pageInfo: PageInfo!
}
无效的 schema 用法
相同的 schema 配置指令不能同时应用于 schema 和对象。以下类型定义为例
type Movie @node {
title: String
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN)
}
type Actor @node @query(read: false, aggregate: true) {
name: String
movies: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT)
}
extend schema @query(read: true, aggregate: false)
这样的配置会提示错误 "@query directive already defined at the schema location"
。