2016-10-23 1 views
0

그래서 저는 레일 위의 루비 작업을하고 있습니다. 내 코드 :Graphql에서 동적 변수를 정의하는 방법은 무엇입니까?

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은 다른 것을 반환해야합니다. 내가 가진

+0

한 가지 중요한 메모를 변경을 통해 내 문제를 해결했다. ** $ **로 시작하는 변수를 사용하지 마십시오. Ruby에서 글로벌 변수로 간주되는 변수이므로, 그 때문에 실제로 예상치 못한 동작에 직면 할 수 있습니다! –

+0

@ Fire-Dragon-DoL : 이것들은 Ruby 변수가 아닙니다. 그것들은 GRAPHQL 내부의 GraphQL 쿼리 내부에있는 GRAPHQL 변수입니다. – CommonsWare

+0

오, 이런, 미안, 나는 완전히 그것을 용서, 저를 용서하십시오! 구문 하이라이트가 나를 속임수로 추측 한 것 같아요. –

답변

0

result = Client.query Query ===>result = Client.query Query, variables: { message: "hello" }

관련 문제