1

我可以在 config/lighthouse.php 中注册多个模式文件吗

在 config/lighthouse.php

'schema' => [
    'register' => base_path('graphql/schema.graphql'),
],
4

2 回答 2

2

不,但您可以使用模式导入

假设您创建了这样的架构文件:

graphql/
|-- schema.graphql
|-- user.graphql

在本例中,Lighthouse 从单个入口点读取您的模式schema.graphql。您可以从那里导入其他架构文件,以将您的架构拆分为多个文件。

type Query {
  user: User
}

#import user.graphql

导入始终以单独的行开头#import,后跟导入文件的相对路径。的内容user.graphql粘贴在最终模式中。

type Query {
  user: User
}

type User {
    name: String!
}

导入语句以递归方式执行,因此即使是最复杂的模式也很容易组织。

您还可以使用通配符导入语法导入多个文件。例如,如果您有这样的架构文件:

graphql/
  |-- schema.graphql
  |-- post/
    |-- post.graphql
    |-- category.graphql

您可以导入与模式匹配的多个文件,而不是命名每个单独的文件。它将使用 PHP 的glob 函数加载。

#import post/*.graphql
于 2019-11-05T10:51:54.057 回答
0

我遇到了这个,正在寻找解决我的问题的解决方案,其中导入不起作用,即使它们在自己的单独线上。原来我的行分隔符设置为 CR(经典 macOS)。因此,请检查您的行分隔符设置。

于 2020-11-09T14:59:59.387 回答