Closed leoGalani closed 5 years ago
I'm not sure what you refer to by "as a string", but parsed results can only be set to constants, which in Ruby must start with a capitalized letter. Have you tried renaming mutation
to Mutation
?
this looks ok to me, the only thing I can think of is '
around GRAPHQL
, can you try removing that? or switch to something like
%(
mutation createSomething($name: String!, $filter: createSomethingFilterInput!, $frequency: SomethingFrequency!) {
createSomething(name: $name, filter: $filter, frequency: $frequency) {
success
message
__typename
}
})
I should've been more clear on what I was really referring to by mutation
, but I was referring to the local variable mutation
in Ruby, not the one in the actual GraphQL query:
-mutation = @client.parse <<-'GRAPHQL'
+Mutation = @client.parse <<-'GRAPHQL'
The single quotes around GRAPHQL
is valid Ruby syntax:
foo = <<-'GRAPHQL'
text
GRAPHQL
# => " text\n"
Hello! Thanks for the support. I'm actually using a lambda function to define my constant.
I was talking with a friend and he gave me some light on how operations work and seem like if I define a name for my mutation operation, it doesn't work.
mutation createSomething($name: String!, $filter: createSomethingFilterInput!, $frequency: SomethingFrequency!) { ...
throws constant name error.
mutation CreateSomething($name: String!, $filter: createSomethingFilterInput!, $frequency: SomethingFrequency!) { ....
create a module class, not a #<GraphQL::Client::OperationDefinition:...>
mutation($name: String!, $filter: createSomethingFilterInput!, $frequency: SomethingFrequency!) { ...
Works just fine.
interesting! so parse
in Graphlient
underneath uses graphql-client
to parse the query, if you pass in a block, it will first try to create query string from it and otherwise it will just pass it to the underneath parse
method. Looking at their examples i don't see them using mutation or query alias.
On the other hand, i don't think you'd need that mutation name necessarily, that only changes how you access the results of that mutation and adds a createSomething
to response path. so instead of response.data.data...
you'd access thing using response.data.create_someting
. Unless you are planning to have multiple mutation per one request, i don't think you'd need that alias. Hope this helps 💚
My team uses mutation names to track down possible issues @ datadog... if the operation doesn't have a name, it's a bit harder to debug* :)
Thanks again for the support!
@leoGalani , Sorry haven't had a chance to look at this yet, did you figure out how to fix it? I was hoping to create a failing spec and go from there.
I didn't have time to stop and look at how the parsing goes. Once I finish my mid tasks, I will fork your repo and try some stuff out and then come with a PR :)
For now, I don't mind not having an operation name 😅
We have an around for this by using https://github.com/tools-aoeur/graphlient/pull/1.
We have an around for this by using tools-aoeur#1.
@ashkan18 - this fork works perfectly for me. I was encountering the same issue in trying to use query/mutation aliases and not getting the correct object type back (orphaned Module instance).
I'm guessing that graphql-client doesn't permit them as they expect the constant returned from parsing to function as the alias. However, as others have mentioned, for logging/debugging/observability, the alias needs to be preserved in whatever is sent for execution.
Can someone PR the fix (and other changes on the fork) here?
Hi!
I'm trying to set a mutation as a 'string' but I'm getting
NameError: wrong constant name createSomething
Here is an example of my code:
But the same
mutation
works using graphql playground.I'm trying to avoid the use of Blocks as I want to maintain a standard on my code.