-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support for query variables #154
Comments
The GraphQL object accepts variables aka arguments |
I've expanded the provided example for a bit more context. When I put a variable named When I provide the values statically, the framework automatically puts them into the arguments map. For example, this works.
And I see no mechanism to set them in graphql-java currently. I could easily write a wrapper in my service to parse JSON response and stick the variable definitions somewhere. There doesn't appear to be a place though. If I'm corrected, I'll happily submit a PR to the README that documents how to do this. |
So I just found your TODO MVC example, and see that you do in fact use variables as described above (https://github.com/graphql-java/todomvc-relay-java/blob/master/src/main/java/todomvc/GraphQLController.java#L33-L34). And also it seems to be working fine for me now. Maybe I just needed to clean & rebuild or something. Working on a PR to update README as promised. |
I submitted a PR to README to document how variables are supported. Not sure when / if that will merge, so I'm just closing this issue. I have my graphql-Java server working with relay following advice from @danielkwinsor. Thanks! |
Are variables really supported? Maybe I am missing something, but the following code always results in an error "Validation error of type UndefinedVariable: Undefined variable personId"
The following works without problems:
I am using graphql-java 4.0 |
I have the exact same problem with version 4.1. |
@DevTomK @SebastianWjertzoch variables are fully supported ... your query is wrong. you have to declare each variable with type ... for example: query nameOfTheQuery($nameOfTheVariable: Int) {
foo(someArgument: $nameOfTheVariable)
} |
We both use the ExecutionInput. So type declaration is not part of the query. Like this ExecutionInput input = ExecutionInput.newExecutionInput(). |
@SebastianWjertzoch as mentioned above: you have to declare the variable. you query is query { person(id: $personId) { id, name } } but it is missing the declaration of the variable. It should like this: query myQuery($personId: Int) { person(id: $personId) { id, name } } I hope this helps |
Ok. So i have to build an special query for every kind of request. I was confused because this: |
well ... if you wanna use a variable you have to declare the variable. the query you mention works fine, because you don't use a variable, hence you don't have to declare it. |
It looks like express-graphql and graphql-ruby accept queries with query and variables in separate structures. For example, here is a query generated by the express-graphql client library.
Here are a couple articles discussing variables:
It doesn't look like the graphql-java server accepts query variables like this currently. It seems like this would be a nice feature to have, so you can use graphql-java servers with the relay-starter-kit.
The text was updated successfully, but these errors were encountered: