0

我有带有子模块的 Laravel 项目我必须在每个模块中为单独的路由创建 graphql 文件。

如何像在 Provider 中注册路由一样,分别为所有模块注册 graphql?如何处理多个模块中的graphql文件?

4

2 回答 2

0

只是另一种方式......我的代码也按模块拆分,我的 ServiceProvider 中有这样的东西:


public function __construct(Application $app)
    {
        parent::__construct($app);
        $reflection = new ReflectionClass($this);
        $this->folder = dirname($reflection->getFileName());
    }

public function bootGraphql()
    {
        $graphql = $this->folder.'/Graphql/module_schema.graphql';
        if (file_exists($graphql)) {
            Event::listen(BuildSchemaString::class, function () use ($graphql) {
                return (new SchemaStitcher($graphql))->getSchemaString();
            });
        }
    }

然后,在你的module_schema.graphql你也可以使用#import */*.graphql. 因此.graphql,您Graphql文件夹中的每个文件都已加载。

于 2020-02-11T15:29:51.467 回答
0

您可以通过使用包含来做到这一点。例如,在我正在处理的项目中,graphql 文件按实体拆分。我们像这样导入它们:

#import ../Entities/*/*.graphqls

请注意,导入是相对于模式文件的位置的。

有关更多信息,请参阅文档

于 2020-02-10T13:16:26.417 回答