Commit 5ef68579 authored by charlie ablett's avatar charlie ablett

Refactor echo resolver

- use current_user method
- add GraphQL type
- add a field options test
- refactor test
parent 454ba65e
......@@ -2,15 +2,16 @@
module Resolvers
class EchoResolver < BaseResolver
type ::GraphQL::STRING_TYPE, null: false
description 'Testing endpoint to validate the API with'
argument :text, GraphQL::STRING_TYPE, required: true,
description: 'Text to echo back'
def resolve(**args)
username = context[:current_user]&.username
def resolve(text:)
username = current_user&.username
"#{username.inspect} says: #{args[:text]}"
"#{username.inspect} says: #{text}"
end
end
end
......@@ -8,6 +8,13 @@ RSpec.describe Resolvers::EchoResolver do
let(:current_user) { create(:user) }
let(:text) { 'Message test' }
specify do
expect(described_class.field_options).to include(
type: eq(::GraphQL::STRING_TYPE),
null: be_falsey
)
end
describe '#resolve' do
it 'echoes text and username' do
expect(resolve_echo(text)).to eq %Q("#{current_user.username}" says: #{text})
......
......@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe 'GraphQL' do
include GraphqlHelpers
let(:query) { graphql_query_for('echo', 'text' => 'Hello world' ) }
let(:query) { graphql_query_for('echo', text: 'Hello world' ) }
context 'logging' do
shared_examples 'logging a graphql query' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment