如何在 Blazor 项目中使用 Strawberry Shake 从 GraphQL 正确生成 C# 脚本

发布于 2025-01-13 19:15:36 字数 1858 浏览 1 评论 0原文

我正在使用 .NET Core 5 &布拉泽在一起。我还创建了一个漂亮简单的 GraphQL API。但首先,我只是按照教程Strawberry Shake 和 Blazor 入门进行操作。对了,草莓奶昔的版本是12.7.0。我完美地遵循了教程,但无法正确生成脚本。

1.  dotnet new tool-manifest
2.  dotnet tool install StrawberryShake.Tools --local
3.  dotnet new sln -n Demo
4.  dotnet new wasm -n Demo
5.  dotnet sln add ./Demo
6.  dotnet add Demo package StrawberryShake.Transport.Http
7.  dotnet add Demo package StrawberryShake.CodeGeneration.CSharp.Analyzers
8.  dotnet add Demo package Microsoft.Extensions.DependencyInjection
9.  dotnet add Demo package Microsoft.Extensions.Http
10. dotnet graphql init https://workshop.chillicream.com/graphql/ -n ConferenceClient -p ./Demo 
11. Added a namespace 

{
  "schema": "schema.graphql",
  "documents": "**/*.graphql",
  "extensions": {
    "strawberryShake": {
      "name": "ConferenceClient",
      "namespace": "Demo.GraphQL",
      "url": "https://workshop.chillicream.com/graphql/",
      "dependencyInjection": true
    }
  }
}

12. added a graphql file with query

query GetSessions {
  sessions(order: { title: ASC }) {
    nodes {
      title
    }
  }
}

13. dotnet build

这是输出生成的文件的样子。

输入图片此处描述

这更符合我观看后的预期此视频

在此处输入图像描述

显然,这是一个不同的 API,但我尝试在几个 API(包括我自己的 API)上生成,肯定出现了严重错误。我该怎么做才能获得格式良好的代码。我很确定我的 API 非常标准。我按照GraphQL 和 Hot Chocolate 的视频来创建我的视频。

I am using a .NET Core 5 & Blazor together. I have also created a nice simple GraphQL API. But to start I just followed the tutorial Getting Started With Strawberry Shake and Blazor. By the way, the version of Strawberry Shake is 12.7.0. I followed the tutorial perfectly but I can't get the scripts to generate properly.

1.  dotnet new tool-manifest
2.  dotnet tool install StrawberryShake.Tools --local
3.  dotnet new sln -n Demo
4.  dotnet new wasm -n Demo
5.  dotnet sln add ./Demo
6.  dotnet add Demo package StrawberryShake.Transport.Http
7.  dotnet add Demo package StrawberryShake.CodeGeneration.CSharp.Analyzers
8.  dotnet add Demo package Microsoft.Extensions.DependencyInjection
9.  dotnet add Demo package Microsoft.Extensions.Http
10. dotnet graphql init https://workshop.chillicream.com/graphql/ -n ConferenceClient -p ./Demo 
11. Added a namespace 

{
  "schema": "schema.graphql",
  "documents": "**/*.graphql",
  "extensions": {
    "strawberryShake": {
      "name": "ConferenceClient",
      "namespace": "Demo.GraphQL",
      "url": "https://workshop.chillicream.com/graphql/",
      "dependencyInjection": true
    }
  }
}

12. added a graphql file with query

query GetSessions {
  sessions(order: { title: ASC }) {
    nodes {
      title
    }
  }
}

13. dotnet build

Here is what the output generated files look like.

enter image description here

This is more of what I was expecting after watching this video

enter image description here

Obviously, it is a different API but I have tried generating on a couple APIs including my own and surely something is horribly wrong. What can I do to get the nicely formatted code. I am pretty sure my API is pretty standard. I followed a video about GraphQL and Hot Chocolate to create mine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文