【问题标题】:How to generate Typescript types for queries including Apollo @client and @rest directives using Apollo tooling?如何使用 Apollo 工具为查询生成 Typescript 类型,包括 Apollo @client 和 @rest 指令?
【发布时间】:2020-02-07 16:47:57
【问题描述】:

我在src/schema.graphql 中有一个客户端架构,在src/graphql/queries.ts 中有一些查询。

目前,我的所有查询都包括@rest directive from apollo-link-rest,我正在尝试使用apollo client:codegen 使用以下命令为它们生成Typescript 类型:

apollo client:codegen ./src/__generated__/types.ts --outputFlat --includes=./src/**/queries.ts --addTypename --localSchemaFile=./src/schema.graphql --target=typescript

这总是会导致

.../src/graphql/queries.ts: Unknown directive "rest".
ToolError: Validation of GraphQL query document failed

我不明白我做错了什么。根据the docs here Apollo 应该支持@client@rest 开箱即用的客户端指令。

有没有人使用@rest@client 指令成功生成查询类型?

【问题讨论】:

    标签: typescript graphql apollo apollo-client


    【解决方案1】:

    嗯,后面是一堆文档页面,如果我在src/schema.graphql 中声明指令如下,它似乎可以工作:

    directive @rest(
        type: String!
        path: String!
        method: String
    ) on FIELD
    

    注意:此声明不包括所有可能的参数。参考docs for the complete list of arguments

    谁能确认这是正确的做法?

    【讨论】:

      猜你喜欢
      • 2019-11-16
      • 2018-11-24
      • 2020-06-07
      • 2019-06-08
      • 2021-01-15
      • 2018-07-18
      • 2018-02-10
      • 2020-12-06
      • 2018-07-04
      相关资源
      最近更新 更多