Giter Site home page Giter Site logo

Comments (6)

kented avatar kented commented on August 30, 2024 2

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

from apollo-federation-ruby.

kented avatar kented commented on August 30, 2024 1

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.

from apollo-federation-ruby.

daemonsy avatar daemonsy commented on August 30, 2024 1

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.

from apollo-federation-ruby.

bilby91 avatar bilby91 commented on August 30, 2024

@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.

from apollo-federation-ruby.

BatuhanW avatar BatuhanW commented on August 30, 2024

@kented Would you mind sharing your approach?

from apollo-federation-ruby.

kented avatar kented commented on August 30, 2024

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

from apollo-federation-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.