-
Notifications
You must be signed in to change notification settings - Fork 46
Description
This is more my ignorance than an issue.
I am currently using graphql-client but graphlient's block syntax and info on testing make me want to switch over, but I am still not sure how to test my code.
I have a deployed GraphQL server. I can run a query in Postman and get a JSON response.
I copied that response into a string.
I want to consume that endpoint in my rspec test but I want to use the canned JSON response I copied.
stub_request(:post, "http://user:password@example.com")
.to_return(status: 200, body: canned_body, headers: {})
def canned_body
'{ "data": {"some": "json"} }'
end
This errors:
Schema = GraphQL::Client.load_schema(HTTP)
KeyError: key not found: "data"
from /Users/bgreeff/.rvm/gems/ruby-2.6.1/gems/graphql-1.9.6/lib/graphql/schema/loader.rb:16:in `fetch'
One issue is that my stub runs after Schema = GraphQL::Client.load_schema(HTTP)
This seems like a design flaw, making my test improbable.
I see your example
stub_request(:post, url).to_return(
status: 200,
body: DummySchema.execute(GraphQL::Introspection::INTROSPECTION_QUERY).to_json
)
I am guessing this is because there are actually 2 requests to the server, 1 to load the schema, but I have no idea how this works.
Can you provide a little more info on how I should construct my test please.