Hotchocolate Strawberryshake 如何使用突变?

问题描述

似乎根本没有关于如何使用 Strawberryshake (C#) 由 graphql 客户端进行突变的示例。使用 Strawberryshake Version11.0.0-preview.138、Abstractions and Http v. 10.3.0-preview.12 和 CodeGeneration.CSharp.Analyzers v. 0.0.30,我可以从 example 运行查询就好了。现在我添加了一个突变,但我不知道如何使用它?

我从架构导入 (Alarm.graphql) 中得到以下信息:

schema {
  query: Query
  mutation: Mutation
}

type Query {
  alarms: [Alarm]
}

type Mutation {
  addAlarm(input: AlarmInput): AlarmPayload
}

type AlarmPayload {
  alarm: Alarm
}

type Alarm {
  id: Int!
  handle: Int!
  messageId: Int!
  message: String
}

input AlarmInput {
  id: Int!
  handle: Int!
  messageId: Int!
  message: String
}

查询使用

query getAlarms {
    alarms {
        message
    }
}

就好了。对于我添加的突变

mutation writeAlarm {
    addAlarm {
       alarm {
            id
            handle
            messageId
            message
        }
    }
}

它成功地在构建时生成了很多看起来很合理的类。现在我创建到服务器的连接:

var serviceCollection = new ServiceCollection();
serviceCollection.AddHttpClient(
"ConnectorLogGraphQL",c => c.BaseAddress = new Uri("http://localhost:5000/graphql"));
serviceCollection.AddAlarmClient();
var services = serviceCollection.BuildServiceProvider();
IAlarmClient client = services.GetRequiredService<IAlarmClient>();

客户端是我需要使用的。对于查询,我可以使用:

var result = await client.GetAlarmsAsync();

同样

var result = await client.WriteAlarmAsync();

编译得很好,但当然它不会做我想要的。定义了一些 WriteAlarmOperation,我可以将其作为参数传递给 WriteAlarmAsync,但此操作也没有用于输入的字段。少了点什么..?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...