如何在 Graphql 上定义动态变量?

How to define dynamic variables on Graphql?

所以,我正在 rails 上 ruby。这是我的代码:

require 'graphql/client'
require 'graphql/client/http'

HTTP = GraphQL::Client::HTTP.new("Graph-API-Web-Site")
Schema = GraphQL::Client.load_schema(HTTP)
Client = GraphQL::Client.new(schema: Schema,execute: HTTP)


Query = Client.parse <<-'GRAPHQL'
  query($message: String = "Hello") {
    stickers(query: $message, first: 21, after: "") {
      edges {
        node {
          fileUrl(fullWatermarked: true)
        }
      }
    }
  }
GRAPHQL


result = Client.query Query

puts result.data.inspect

如何给贴纸 {query: .....} 区域赋予特定的价值?我想通过程序运行更改消息的值。例如,当消息更改时,Client.query 应该 return 有所不同。

我刚刚通过更改 result = Client.query Query ===> result = Client.query Query, variables: { message: "hello" }

解决了我的问题