Skip to content

Instantly share code, notes, and snippets.

@kayinrage
Last active April 3, 2019 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kayinrage/f668ba82b492058e47bc26dcf56fb5e2 to your computer and use it in GitHub Desktop.
Save kayinrage/f668ba82b492058e47bc26dcf56fb5e2 to your computer and use it in GitHub Desktop.
GraphQL with Ruby On Rails: Queries in Multiple Files
require 'rails_helper'
module Queries
RSpec.describe Book, type: :request do
describe '.resolve' do
it 'returns book for provided id' do
author = create(:author)
book = create(:book, author: author, title: 'Hero', publication_date: 1984, genre: 'Horror')
post '/graphql', params: { query: query(id: book.id) }
json = JSON.parse(response.body)
data = json['data']['book']
expect(data).to include(
'id' => be_present,
'title' => 'Hero',
'publicationDate' => 1984,
'genre' => 'Horror',
'author' => { 'id' => author.id.to_s }
)
end
end
def query(id:)
<<~GQL
query {
book(id: #{id}) {
id
title
publicationDate
genre
author {
id
}
}
}
GQL
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment