简体   繁体   English

从 postgraphile GraphQL 程序生成的查询/突变

[英]Procedurally generated queries/mutations from postgraphile GraphQL

I don't believe its a big deal, but my GraphIQL generates all of its queries and mutations from my PSQL schema.我不相信这有什么大不了的,但我的 GraphIQL 从我的 PSQL 模式生成所有查询和突变。 Is it possible to have it general a file for me with each change that I can use directly in my project?对于我可以直接在我的项目中使用的每个更改,是否可以为我提供一个通用文件? As currently I am having to write manually my queries/mutations as below and often I am changing the schema and then having to update all my instances of this.由于目前我必须手动编写我的查询/突变,如下所示,并且我经常更改架构,然后必须更新我的所有实例。

export const UPDATE = gql`
  mutation updateOrganiserByOrganiserId(
    $organiserName: String!
    $address: String
    $address2: String
    $city: String
    $country: String
    $postCode: String
    $manufacturerId: Int
    $organiserId: Int!
    $competitionSystemId: Int!
  ) {
    updateOrganiserByOrganiserId(
      input: {
        clientMutationId: "updateOrganisation"
        organiserId: $organiserId
        organiserPatch: {
          organiserName: $organiserName
          address: $address
          address2: $address2
          city: $city
          country: $country
          postCode: $postCode
          manufacturerId: $manufacturerId
          competitionSystemId: $competitionSystemId
        }
      }
    ) {
      clientMutationId
    }
  }
`

No, there is no way to do that.不,没有办法做到这一点。

often I am changing the schema我经常改变架构

That's your actual problem.那是你的实际问题。 Your schema should be immutable, and only ever be extended but never changed.您的架构应该是不可变的,并且只能扩展但永远不会更改。 From the GraphQL best practices on versioning : " new capabilities can be added via new types and new fields on those types without creating a breaking change. This has led to a common practice of always avoiding breaking changes and serving a versionless API. "来自GraphQL 关于版本控制的最佳实践:“可以通过这些类型的新类型和新字段添加新功能,而不会产生重大更改。这导致了始终避免重大更改并提供无版本 API 的常见做法。

So even when your Postgres database schema changes, keep your GraphQL schema the same (or add new fields to it) so that your mutations simply keep working.因此,即使您的 Postgres 数据库架构发生更改,也要保持您的 GraphQL 架构相同(或向其中添加新字段),以便您的突变继续工作。 Postgraphile provides a great lot of tools (renaming of fields, deprecation annotations, computed fields, …) to support that. Postgraphile 提供了大量工具(重命名字段、弃用注释、计算字段……)来支持这一点。

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

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