可以将wisper与Ruby GraphQL集成吗?

如何解决可以将wisper与Ruby GraphQL集成吗?

我希望将Wisper与现有的graphql api仅ruby on rails项目集成在一起。只是想知道是否有任何方法可以广播来自graphql突变的事件?

module Mutations
  module Order
    include Wisper::Publisher
    class Create < ::Mutations::BaseMutation
      argument :id,ID,required: true
      argument :date,String,required: true
      argument :category,required: true

      type Types::OrderType

      def resolve(**attributes)
        order = Order.new(attributes)
        if order.save!
          broadcast(:order_creation_successful,order.id)
          order
        end
      end
    end
  end
end

全球订户

Rails.application.config.to_prepare do
  Wisper.clear if Rails.env.development? || Rails.env.test?

  Wisper.subscribe(
    OrderService::HandleExternalCalls,async: true,on: %i[order_creation_successful]
  )
end

输出-NoMethodError(调用#GraphqlController的私有方法“广播”)

错误跟踪:

{
"status": 500,"error": "Internal Server Error","exception": "#<NoMethodError: undefined method `broadcast' for #<Mutations::Order::Create:0x00007f4b29492a70>>","traces": {
"Application Trace": [
{
"exception_object_id": 69980396152400,"id": 0,"trace": "app/graphql/mutations/order/create.rb:31:in `resolve'"
},{
"exception_object_id": 69980396152400,"id": 57,"trace": "app/controllers/graphql_controller.rb:14:in `execute'"
}
],"Framework Trace": [
{
"exception_object_id": 69980396152400,"id": 1,"trace": "graphql (1.11.2) lib/graphql/schema/resolver.rb:95:in `public_send'"
},"id": 2,"trace": "graphql (1.11.2) lib/graphql/schema/resolver.rb:95:in `block (3 levels) in resolve_with_support'"
},"id": 3,"trace": "graphql (1.11.2) lib/graphql/schema.rb:112:in `after_lazy'"
},"id": 4,"trace": "graphql (1.11.2) lib/graphql/schema/resolver.rb:83:in `block (2 levels) in resolve_with_support'"
},"id": 5,"id": 6,"trace": "graphql (1.11.2) lib/graphql/schema/resolver.rb:76:in `block in resolve_with_support'"
},"id": 7,"id": 8,"trace": "graphql (1.11.2) lib/graphql/schema/resolver.rb:65:in `resolve_with_support'"
},"id": 9,"trace": "graphql (1.11.2) lib/graphql/schema/relay_classic_mutation.rb:64:in `resolve_with_support'"
},"id": 10,"trace": "graphql (1.11.2) lib/graphql/schema/field.rb:684:in `public_send'"
},"id": 11,"trace": "graphql (1.11.2) lib/graphql/schema/field.rb:684:in `block in public_send_field'"
},"id": 12,"trace": "graphql (1.11.2) lib/graphql/schema/field.rb:720:in `with_extensions'"
},"id": 13,"trace": "graphql (1.11.2) lib/graphql/schema/field.rb:666:in `public_send_field'"
},"id": 14,"trace": "graphql (1.11.2) lib/graphql/schema/field.rb:579:in `block in resolve'"
},"id": 15,"id": 16,"trace": "graphql (1.11.2) lib/graphql/schema/field.rb:577:in `resolve'"
},"id": 17,"trace": "graphql (1.11.2) lib/graphql/execution/interpreter/runtime.rb:224:in `block (5 levels) in evaluate_selections'"
},"id": 18,"trace": "graphql (1.11.2) lib/graphql/tracing.rb:66:in `trace'"
},"id": 19,"trace": "graphql (1.11.2) lib/graphql/execution/interpreter/runtime.rb:223:in `block (4 levels) in evaluate_selections'"
},"id": 20,"trace": "graphql (1.11.2) lib/graphql/query.rb:353:in `block in with_error_handling'"
},"id": 21,"trace": "graphql (1.11.2) lib/graphql/execution/errors.rb:41:in `with_error_handling'"
},"id": 22,"trace": "graphql (1.11.2) lib/graphql/query.rb:352:in `with_error_handling'"
},"id": 23,"trace": "graphql (1.11.2) lib/graphql/execution/interpreter/runtime.rb:222:in `block (3 levels) in evaluate_selections'"
},"id": 24,"trace": "graphql (1.11.2) lib/graphql/execution/interpreter/runtime.rb:384:in `resolve_with_directives'"
},"id": 25,"trace": "graphql (1.11.2) lib/graphql/execution/interpreter/runtime.rb:219:in `block (2 levels) in evaluate_selections'"
},"id": 26,"trace": "graphql (1.11.2) lib/graphql/execution/interpreter/runtime.rb:459:in `after_lazy'"
},"id": 27,"trace": "graphql (1.11.2) lib/graphql/execution/interpreter/runtime.rb:177:in `block in evaluate_selections'"
},"id": 28,"trace": "graphql (1.11.2) lib/graphql/execution/interpreter/runtime.rb:124:in `each'"
},"id": 29,"trace": "graphql (1.11.2) lib/graphql/execution/interpreter/runtime.rb:124:in `evaluate_selections'"
},"id": 30,"trace": "graphql (1.11.2) lib/graphql/execution/interpreter/runtime.rb:60:in `run_eager'"
},"id": 31,"trace": "graphql (1.11.2) lib/graphql/execution/interpreter.rb:73:in `block in evaluate'"
},"id": 32,"id": 33,"trace": "graphql (1.11.2) lib/graphql/execution/interpreter.rb:72:in `evaluate'"
},"id": 34,"trace": "graphql (1.11.2) lib/graphql/execution/interpreter.rb:45:in `begin_query'"
},"id": 35,"trace": "graphql (1.11.2) lib/graphql/execution/multiplex.rb:112:in `begin_query'"
},"id": 36,"trace": "graphql (1.11.2) lib/graphql/execution/multiplex.rb:83:in `block in run_as_multiplex'"
},"id": 37,"trace": "graphql (1.11.2) lib/graphql/execution/multiplex.rb:82:in `map'"
},"id": 38,"trace": "graphql (1.11.2) lib/graphql/execution/multiplex.rb:82:in `run_as_multiplex'"
},"id": 39,"trace": "graphql (1.11.2) lib/graphql/execution/multiplex.rb:61:in `block (2 levels) in run_queries'"
},"id": 40,"trace": "graphql (1.11.2) lib/graphql/execution/multiplex.rb:195:in `block in instrument_and_analyze'"
},"id": 41,"trace": "graphql (1.11.2) lib/graphql/execution/instrumentation.rb:29:in `block (2 levels) in apply_instrumenters'"
},"id": 42,"trace": "graphql (1.11.2) lib/graphql/execution/instrumentation.rb:46:in `block (2 levels) in each_query_call_hooks'"
},"id": 43,"trace": "graphql (1.11.2) lib/graphql/execution/instrumentation.rb:41:in `each_query_call_hooks'"
},"id": 44,"trace": "graphql (1.11.2) lib/graphql/execution/instrumentation.rb:45:in `block in each_query_call_hooks'"
},"id": 45,"trace": "graphql (1.11.2) lib/graphql/execution/instrumentation.rb:72:in `call_hooks'"
},"id": 46,"trace": "graphql (1.11.2) lib/graphql/execution/instrumentation.rb:44:in `each_query_call_hooks'"
},"id": 47,"trace": "graphql (1.11.2) lib/graphql/execution/instrumentation.rb:27:in `block in apply_instrumenters'"
},"id": 48,"id": 49,"trace": "graphql (1.11.2) lib/graphql/execution/instrumentation.rb:26:in `apply_instrumenters'"
},"id": 50,"trace": "graphql (1.11.2) lib/graphql/execution/multiplex.rb:174:in `instrument_and_analyze'"
},"id": 51,"trace": "graphql (1.11.2) lib/graphql/execution/multiplex.rb:60:in `block in run_queries'"
},"id": 52,"id": 53,"trace": "graphql (1.11.2) lib/graphql/execution/multiplex.rb:58:in `run_queries'"
},"id": 54,"trace": "graphql (1.11.2) lib/graphql/execution/multiplex.rb:48:in `run_all'"
},"id": 55,"trace": "graphql (1.11.2) lib/graphql/schema.rb:1642:in `multiplex'"
},"id": 56,"trace": "graphql (1.11.2) lib/graphql/schema.rb:1613:in `execute'"
},"id": 58,"trace": "actionpack (6.0.3.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'"
},"id": 59,"trace": "actionpack (6.0.3.1) lib/abstract_controller/base.rb:195:in `process_action'"
},"id": 60,"trace": "actionpack (6.0.3.1) lib/action_controller/metal/rendering.rb:30:in `process_action'"
},"id": 61,"trace": "actionpack (6.0.3.1) lib/abstract_controller/callbacks.rb:42:in `block in process_action'"
},"id": 62,"trace": "activesupport (6.0.3.1) lib/active_support/callbacks.rb:135:in `run_callbacks'"
},"id": 63,"trace": "actionpack (6.0.3.1) lib/abstract_controller/callbacks.rb:41:in `process_action'"
},"id": 64,"trace": "actionpack (6.0.3.1) lib/action_controller/metal/rescue.rb:22:in `process_action'"
},"id": 65,"trace": "actionpack (6.0.3.1) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'"
},"id": 66,"trace": "activesupport (6.0.3.1) lib/active_support/notifications.rb:180:in `block in instrument'"
},"id": 67,"trace": "activesupport (6.0.3.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'"
},"id": 68,"trace": "activesupport (6.0.3.1) lib/active_support/notifications.rb:180:in `instrument'"
},"id": 69,"trace": "actionpack (6.0.3.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'"
},"id": 70,"trace": "actionpack (6.0.3.1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'"
},"id": 71,"trace": "activerecord (6.0.3.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'"
},"id": 72,"trace": "actionpack (6.0.3.1) lib/abstract_controller/base.rb:136:in `process'"
},"id": 73,"trace": "actionpack (6.0.3.1) lib/action_controller/metal.rb:190:in `dispatch'"
},"id": 74,"trace": "actionpack (6.0.3.1) lib/action_controller/metal.rb:254:in `dispatch'"
},"id": 75,"trace": "actionpack (6.0.3.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'"
},"id": 76,"trace": "actionpack (6.0.3.1) lib/action_dispatch/routing/route_set.rb:33:in `serve'"
},"id": 77,"trace": "actionpack (6.0.3.1) lib/action_dispatch/journey/router.rb:49:in `block in serve'"
},"id": 78,"trace": "actionpack (6.0.3.1) lib/action_dispatch/journey/router.rb:32:in `each'"
},"id": 79,"trace": "actionpack (6.0.3.1) lib/action_dispatch/journey/router.rb:32:in `serve'"
},"id": 80,"trace": "actionpack (6.0.3.1) lib/action_dispatch/routing/route_set.rb:834:in `call'"
},"id": 81,"trace": "rack (2.2.3) lib/rack/etag.rb:27:in `call'"
},"id": 82,"trace": "rack (2.2.3) lib/rack/conditional_get.rb:40:in `call'"
},"id": 83,"trace": "rack (2.2.3) lib/rack/head.rb:12:in `call'"
},"id": 84,"trace": "activerecord (6.0.3.1) lib/active_record/migration.rb:567:in `call'"
},"id": 85,"trace": "actionpack (6.0.3.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'"
},"id": 86,"trace": "activesupport (6.0.3.1) lib/active_support/callbacks.rb:101:in `run_callbacks'"
},"id": 87,"trace": "actionpack (6.0.3.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'"
},"id": 88,"trace": "actionpack (6.0.3.1) lib/action_dispatch/middleware/executor.rb:14:in `call'"
},"id": 89,"trace": "actionpack (6.0.3.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'"
},"id": 90,"trace": "actionpack (6.0.3.1) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'"
},"id": 91,"trace": "actionpack (6.0.3.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'"
},"id": 92,"trace": "railties (6.0.3.1) lib/rails/rack/logger.rb:37:in `call_app'"
},"id": 93,"trace": "railties (6.0.3.1) lib/rails/rack/logger.rb:26:in `block in call'"
},"id": 94,"trace": "activesupport (6.0.3.1) lib/active_support/tagged_logging.rb:80:in `block in tagged'"
},"id": 95,"trace": "activesupport (6.0.3.1) lib/active_support/tagged_logging.rb:28:in `tagged'"
},"id": 96,"trace": "activesupport (6.0.3.1) lib/active_support/tagged_logging.rb:80:in `tagged'"
},"id": 97,"trace": "railties (6.0.3.1) lib/rails/rack/logger.rb:26:in `call'"
},"id": 98,"trace": "actionpack (6.0.3.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'"
},"id": 99,"trace": "actionpack (6.0.3.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'"
},"id": 100,"trace": "rack (2.2.3) lib/rack/runtime.rb:22:in `call'"
},"id": 101,"trace": "activesupport (6.0.3.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'"
},"id": 102,"id": 103,"trace": "actionpack (6.0.3.1) lib/action_dispatch/middleware/static.rb:126:in `call'"
},"id": 104,"trace": "rack (2.2.3) lib/rack/sendfile.rb:110:in `call'"
},"id": 105,"trace": "actionpack (6.0.3.1) lib/action_dispatch/middleware/host_authorization.rb:82:in `call'"
},"id": 106,"trace": "rack-cors (1.1.1) lib/rack/cors.rb:100:in `call'"
},"id": 107,"trace": "railties (6.0.3.1) lib/rails/engine.rb:527:in `call'"
},"id": 108,"trace": "puma (3.12.6) lib/puma/configuration.rb:227:in `call'"
},"id": 109,"trace": "puma (3.12.6) lib/puma/server.rb:706:in `handle_request'"
},"id": 110,"trace": "puma (3.12.6) lib/puma/server.rb:476:in `process_client'"
},"id": 111,"trace": "puma (3.12.6) lib/puma/server.rb:334:in `block in run'"
},"id": 112,"trace": "puma (3.12.6) lib/puma/thread_pool.rb:135:in `block in spawn_thread'"
}
],"Full Trace": [
{
"exception_object_id": 69980396152400,.
.
.
]
}
}

还有其他替代宝石可以实现这一目标吗?

解决方法

您得到的异常实际上是:

#<NoMethodError: undefined method `broadcast' for #<Mutations::Order::Create:0x00007f4b29492a70>>

broadcast宝石似乎添加了wisper方法。您已将Wisper::Publisher包含在Mutations::Order 模块中:

module Mutations
  module Order
    include Wisper::Publisher
    class Create < ::Mutations::BaseMutation
      # stuff
      def resolve(**attributes)
        # stuff
      end
    end
  end
end

,并且错误告诉您Mutations::Order::Create对象没有定义broadcast方法。您可能想改为执行此操作:

    class Create < ::Mutations::BaseMutation      
      include Wisper::Publisher # will define the `broadcast` method

      # stuff
      def resolve(**attributes)
        # stuff
      end
    end

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-