Created
September 20, 2019 15:52
-
-
Save jturkel/bf40ba28ccf7a5686136a92590312894 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/inline' | |
gemfile(true) do | |
source 'https://rubygems.org' | |
gem 'graphql', '1.9.12' | |
gem 'rspec' | |
end | |
require 'rspec/autorun' | |
class TestAnalyzer < GraphQL::Analysis::AST::Analyzer | |
def result | |
raise "Gah! I'm a bug" | |
end | |
end | |
module TestInstrumentation | |
extend self | |
def use(schema) | |
schema.instrument(:query, self) | |
end | |
def before_query(_query) | |
# not used | |
end | |
def after_query(query) | |
# Uncomment the following to avoid infinite recursion | |
# return unless query.instance_variable_get(:@executed) | |
query_result = query.result | |
query_result['extensions'] ||= {} | |
query_result['extensions']['hello'] = 'world' | |
end | |
end | |
class TestQueryType < GraphQL::Schema::Object | |
field :ping, String, null: false | |
def ping | |
'ok' | |
end | |
end | |
class TestSchema < GraphQL::Schema | |
use GraphQL::Execution::Interpreter | |
use GraphQL::Analysis::AST | |
use TestInstrumentation | |
query_analyzer TestAnalyzer | |
query TestQueryType | |
end | |
describe do | |
specify do | |
query = <<~GRAPHQL | |
query { | |
ping | |
} | |
GRAPHQL | |
expect { TestSchema.execute(query) }.to raise_error("Gah! I'm a bug") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment