Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to test/confirm federation implementation? #74

Closed
kented opened this issue Jun 4, 2020 · 6 comments
Closed

How to test/confirm federation implementation? #74

kented opened this issue Jun 4, 2020 · 6 comments

Comments

@kented
Copy link

kented commented Jun 4, 2020

Thanks for this gem, I think it will do just what I need. I've added the gem to my app and followed the steps for updating my schema and classes. Is there any documentation in regard to how I should test to confirm my changes?

@bilby91
Copy link
Contributor

bilby91 commented Jun 8, 2020

@kented I don't think the project has documentation in regards to that, probably the best approach you can take is integrating your API with the Apollo Gateway and test your queries and mutations. You can also query the _service and _entities fields directly. You can take a look at the tests on how to do that.

@kented
Copy link
Author

kented commented Jun 9, 2020

Managed to test my changes. If it'd be helpful to others, I might be able to contribute some documentation in regard to what an rspec test could look like for apollo federation integration.

@BatuhanW
Copy link

@kented Would you mind sharing your approach?

@kented
Copy link
Author

kented commented Feb 12, 2021

This is how I test the resolver for a model called 'User' in one of the apps I built:

gql_query = 
  <<~GQL
    query entities {
      _entities(representations: [ {__typename: User, id: "123"} ]) {
        ...on User { 
          id
          first_name
          last_name
        }
      }
    }
  GQL

User.create(id: 123, first_name: 'David', last_name: 'HH')
result = DiscussionSchema.execute(gql_query, context: context)
expected_result = [{ 'id' => '123', 'first_name' => 'David', 'last_name' => 'HH' }]
expect(result.dig('data', '_entities')).to eq(expected_result)

I extracted this answer from a more complex test suite I wrote several months ago, so it may contain some errors. Hopefully it provides enough guidance to be helpful.

The gem's test suite also has some examples you can see here: https://github.com/Gusto/apollo-federation-ruby/blob/master/spec/apollo-federation/entities_field_spec.rb#L164

@daemonsy
Copy link
Contributor

daemonsy commented Jan 10, 2022

Hi @kented , your approach was how I tested one of our internal app that's using federation. It works well but can be pretty confusing to someone who has less exposure to federation. But I do like that it creates a relatively honest test.

Maybe in the future, the maintainers might consider some test helpers. For now, I'll try to add a PR that highlights this as a testing strategy, save future readers some time hopefully.

@kented
Copy link
Author

kented commented Jan 11, 2022

Nice. I think what you've added to the README will be helpful to folks who are wondering how to test their implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants