繁体   English   中英

Laravel Lighthouse:如何让 graphql-codegen 从我的模式生成类型?

[英]Laravel Lighthouse: How can I get graphql-codegen to generate typings from my schema?

我在我的 Laravel 应用程序中使用 Laravel 灯塔作为我的 graphql 服务器。 现在我已经在我的 graphql/schema.graphql 文件中添加了自定义查询和类型,我希望能够在我的 TypeScript Vue 3 应用程序中输入类型,该应用程序位于 ZA5C95B86291EA299ZFCBE64 项目中。 但是,当我运行graphql-codegen --config codegen.yml命令时,它会失败,因为生成的查询与架构文件中的内容不匹配。

我的 graphql/schema.graphql 文件中的查询。

type Query {
    posts: [Post!]! @paginate(defaultCount: 10)
}

我在 Vue 组件中调用的查询

            {
                posts {
                    data {
                        uuid
                        body
                        user {
                            name
                        }
                    }
                }
            }

下面的代码是我的 codegen.yml 文件


overwrite: true
schema: "./graphql/schema.graphql"
documents: "./resources/js/pages/**/*.vue"
generates:
  ./resources/js/generated.ts:
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-vue-apollo-smart-ops"

我需要指出的任何想法或如何让 graphql-codegen 生成正确的类型?

您的源模式由诸如@paginate类的指令进行转换。 使用以下 artisan 命令生成包含整个和最终模式的单个文件:

php artisan lighthouse:print-schema

请参阅https://lighthouse-php.com/master/api-reference/commands.html#print-schema

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM