diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-05-21 13:42:07 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-06-05 20:47:42 +0200 |
commit | c443133e779c4c508b9c6429dd4ba623d64f03f1 (patch) | |
tree | 390ec7649b0875f059c0962458319fe14ed8d34c /spec/controllers | |
parent | aa4b1ae71260720b47695b8a256134f20280f61a (diff) | |
download | gitlab-ce-c443133e779c4c508b9c6429dd4ba623d64f03f1.tar.gz |
Handle exceptions outside the GraphQL schema
This allows us to report JSON parse exceptions to clients and ignore
them in sentry.
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/graphql_controller_spec.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/spec/controllers/graphql_controller_spec.rb b/spec/controllers/graphql_controller_spec.rb index d6689dbc3c6..1449036e148 100644 --- a/spec/controllers/graphql_controller_spec.rb +++ b/spec/controllers/graphql_controller_spec.rb @@ -2,6 +2,8 @@ require 'spec_helper' describe GraphqlController do describe 'execute' do + let(:user) { nil } + before do sign_in(user) if user @@ -39,17 +41,26 @@ describe GraphqlController do is_expected.to eq('echo' => '"Simon" says: test success') end end + + context 'invalid variables' do + it 'returns an error' do + run_test_query!(variables: "This is not JSON") + + expect(response).to have_gitlab_http_status(422) + expect(json_response['errors'].first['message']).not_to be_nil + end + end end # Chosen to exercise all the moving parts in GraphqlController#execute - def run_test_query! + def run_test_query!(variables: { 'text' => 'test success' }) query = <<~QUERY query Echo($text: String) { echo(text: $text) } QUERY - post :execute, query: query, operationName: 'Echo', variables: { 'text' => 'test success' } + post :execute, query: query, operationName: 'Echo', variables: variables end def query_response |