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

graphql-ruby: fix create_link_test #1431

Merged
merged 1 commit into from
May 2, 2022
Merged

Conversation

jcat4
Copy link
Contributor

@jcat4 jcat4 commented May 2, 2022

On part 3 of the graphql-ruby tutorial, the code for the Mutations::CreateLinkTest class doesn't run.

Error:
Mutations::CreateLinkTest#test_create_a_new_link:
ArgumentError: wrong number of arguments (given 1, expected 0)
    app/graphql/mutations/create_link.rb:10:in `resolve'
    test/graphql/mutations/create_link_test.rb:6:in `perform'
    test/graphql/mutations/create_link_test.rb:10:in `block in <class:CreateLinkTest>'

This is because the test's perform method takes a keyword argument args, but doesn't splat it before sending it to Mutations::CreateLink#resolve. Because of this, Mutations::CreateLink#resolve is receiving a single hash argument when it expects 2 keyword arguments.

# Mutations::CreateLinkTest
def perform(user: nil, **args)
  Mutations::CreateLink.new(object: nil, field: nil, context: {}).resolve(args)
end
  
# Mutations::CreateLink
def resolve(description: nil, url: nil)
  Link.create!(description: description, url: url)
end

Splatting args fixes the problem!

# Mutations::CreateLinkTest
def perform(user: nil, **args)
  Mutations::CreateLink.new(object: nil, field: nil, context: {}).resolve(**args)
end

@TasinIshmam TasinIshmam merged commit 600073b into howtographql:main May 2, 2022
@TasinIshmam
Copy link
Contributor

TasinIshmam commented May 2, 2022

Thank you! Merged.

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.

None yet

2 participants