Skip to content

Instantly share code, notes, and snippets.

@aarona
Last active July 18, 2024 15:00
Show Gist options
  • Save aarona/17aad4b6269208260da2f2d82dd23937 to your computer and use it in GitHub Desktop.
Save aarona/17aad4b6269208260da2f2d82dd23937 to your computer and use it in GitHub Desktop.
Crucial RSpec test to include when running GraphQL
RSpec.describe GraphQL::Schema::Printer do
describe '#print_schema' do
it 'should not raise an error when called' do
expect { GraphQL::Schema::Printer.print_schema(MyAppSchema) }.to_not raise_error
end
end
end
@aarona
Copy link
Author

aarona commented Jul 15, 2024

GraphQL can be really finicky. For example given the following code:

module Types
  class MutationType < Types::BaseObject
    field :some_a_mutation, mutation: Mutations::ModuleA::SomeMutation
    field :some_b_mutation, mutation: Mutations::ModuleB::SomeMutation
  end
end

Will allow you to create passing specs that test against both of these mutations but according to GraphQL Schema, this is invalid because there are two classes named SomeMuation. It doesn't matter that they're in separate modules.

Including the above test in your test suite will catch errors like this despite individually your tests are passing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment