Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant get variables to work #156

Closed
stigi opened this issue Aug 2, 2016 · 1 comment
Closed

Cant get variables to work #156

stigi opened this issue Aug 2, 2016 · 1 comment

Comments

@stigi
Copy link

stigi commented Aug 2, 2016

Hi,

I'm running a very simple query with a variable, but when execute the schema I get an error that the variable isn't declared, but I pass it in a Hash.

[1] pry(#<Cruise::App>)> query_variables
=> {"channel_id"=>"1"}
[2] pry(#<Cruise::App>)> query_string
=> "{\n channel(id:$channel_id) {\n  id\n }\n}"
[3] pry(#<Cruise::App>)> Schema.execute(query_string, variables: query_variables)
=> {"errors"=>[{"message"=>"Variable $channel_id is used by  but not declared", "locations"=>[{"line"=>2, "column"=>13}]}]}
[4] pry(#<Cruise::App>)> GraphQL::VERSION
=> "0.17.2"

For completeness sake here's my action code. The query comes from a graphiql instance I've set up myself (possible source of errors, but the values arriving in ruby do look ok).

post :index do
  query_string = params['query'] || ""
  query_variables_string = params['variables']
  query_variables = query_variables_string ? JSON.parse(query_variables_string) : {}
  content_type :json
  Schema.execute(query_string, variables: query_variables).to_json
end

Am I doing anything obviously wrong here which I'm to blind to see? What's a good way to further debug this?

Thanks

@stigi
Copy link
Author

stigi commented Aug 2, 2016

Figured out the issue. Had to pass the variable in the query. With an updated query it worked:

query($channel_id: ID!) {
 channel(id: $channel_id) {
   id
 }
}

@stigi stigi closed this as completed Aug 2, 2016
acao pushed a commit to acao/graphiql that referenced this issue Jun 1, 2019
…transform-class-properties-6.24.1

Update babel-plugin-transform-class-properties to the latest version 🚀
acao pushed a commit to acao/graphiql that referenced this issue Jun 5, 2019
…-flowtype-2.35.1

Update eslint-plugin-flowtype to the latest version 🚀
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant