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

Added support for parameterized queries and mutations. #20

Merged
merged 1 commit into from
Oct 20, 2017

Conversation

dblock
Copy link
Collaborator

@dblock dblock commented Oct 18, 2017

On top of #19, added support for parameterized queries and mutations.

Closes #1.

@dblock dblock changed the title Parameterized queries Added support for query variables and parameterized mutations. Oct 18, 2017
@dblock dblock changed the title Added support for query variables and parameterized mutations. Added support for parameterized queries and mutations. Oct 18, 2017
Copy link
Owner

@ashkan18 ashkan18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had one comment/suggestion about how to define variables in our DSL.

On a separate note originally I thought it would be really useful to support parametrized queries and mutations but the more I think about it, it may not be as useful in our case. Basically why would someone do:

client.query(ids: [42]) do
  query(:$ids => :'[Int]') do
    invoices(ids: :$ids) do
      id
      fee_in_cents
    end
  end
end

as opposed to

client.query do
  query do
    invoices(ids: [42]) do
      id
      fee_in_cents
    end
  end
end

As far as i understand, from Graphql server side, they both are processed the same way and there is no benefit in parametrizing the variables over plain query.

Maybe with parametrized approach its easier to share the DSL block?

Regardless its nice to support them, let me know what do you think about my DSL suggestion.


```ruby
client.query(ids: [42]) do
query(:$ids => :'[Int]') do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oo interesting approach, I wonder if we can make this slightly more DSLy by doing things like:

client.query(ids: [42]) do
  query(:ids => [:int]) do
   ....
   end
end

This means on our end we need to detect query variables and add $ to them when generating query. What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, opened #23 for a future improvement.

@dblock
Copy link
Collaborator Author

dblock commented Oct 19, 2017

Two reasons for doing a parameterized query ala version 1 above:

  • It passes variables separately in a different field during POST, so you don't risk injection. This is now supported by this PR.
  • It allows you to pre-parse the query avoiding to have you parse it every single time. This is yet something we have to support in Graphlient, Allow pre-parsing queries #22.

@dblock
Copy link
Collaborator Author

dblock commented Oct 19, 2017

I rebased it, it's ready to merge again.

@dblock dblock mentioned this pull request Oct 19, 2017
@ashkan18 ashkan18 merged commit 6189e1a into ashkan18:master Oct 20, 2017
@dblock dblock deleted the parameterized-queries branch October 20, 2017 14:18
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

Successfully merging this pull request may close these issues.

2 participants