如何在Graphql上定义动态变量? [英] How to define dynamic variables on Graphql?

查看:114
本文介绍了如何在Graphql上定义动态变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在研究轨道上的红宝石.这是我的代码:

So, I am working on ruby on rails. This is my code:

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 应该返回不同的内容.

How can I give specific value to stickers {query: .....} area? I want to change the value of message with program runs. For example when the message changes the Client.query should return something different.

推荐答案

我刚刚通过更改 result = Client.query查询 ===> result = Client.query解决了我的问题查询,变量:{消息:"hello"}

I have just solved my problem via changing result = Client.query Query ===> result = Client.query Query, variables: { message: "hello" }

这篇关于如何在Graphql上定义动态变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆