Skip to content

Commit

Permalink
remove initializer, get config from environment
Browse files Browse the repository at this point in the history
  • Loading branch information
bgentry committed Sep 26, 2017
1 parent 58f75d2 commit fdfa804
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 47 deletions.
7 changes: 5 additions & 2 deletions addon/services/apollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ export default Service.extend({
client: null,
apiURL: alias('options.apiURL'),

// options are injected by an initializer and configured in your environment.js.
options: { apiURL: null },
// options are configured in your environment.js.
options: computed(function() {
const config = getOwner(this).resolveRegistration('config:environment');
return config.apollo;
}),

init() {
this._super(...arguments);
Expand Down
15 changes: 0 additions & 15 deletions app/initializers/apollo.js

This file was deleted.

8 changes: 1 addition & 7 deletions tests/unit/mixins/component-query-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ const { getOwner, Object: EmberObject } = Ember;
moduleFor(
'mixin:component-query-manager',
'Unit | Mixin | component query manager', {
needs: ['service:apollo'],
beforeEach() {
// needed to set up config since initializers don't run here
const options = { apiURL: 'https://test.example/graphql' };
this.register('config:apollo', options, { instantiate: false });
getOwner(this).inject('service:apollo', 'options', 'config:apollo');
},
needs: ['config:environment', 'service:apollo'],
subject() {
let TestObject = EmberObject.extend(ComponentQueryManagerMixin);
this.register('test-container:test-object', TestObject);
Expand Down
8 changes: 1 addition & 7 deletions tests/unit/mixins/route-query-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ moduleFor(
'mixin:route-query-manager',
'Unit | Mixin | route query manager',
{
needs: ['service:apollo'],
beforeEach() {
// needed to set up config since initializers don't run here
const options = { apiURL: 'https://test.example/graphql' };
this.register('config:apollo', options, { instantiate: false });
getOwner(this).inject('service:apollo', 'options', 'config:apollo');
},
needs: ['config:environment', 'service:apollo'],
subject() {
let TestObject = EmberObject.extend(RouteQueryManagerMixin);
this.register('test-container:test-object', TestObject);
Expand Down
23 changes: 7 additions & 16 deletions tests/unit/services/apollo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,29 @@ import ApolloService from 'ember-apollo-client/services/apollo';

const { computed } = Ember;

let options;

moduleFor('service:apollo', 'Unit | Service | apollo', {
beforeEach() {
options = {
apiURL: 'https://test.example/graphql',
};
},
needs: ['config:environment'],
});

test('it exists', function(assert) {
let options = {
apiURL: 'https://test.example/graphql',
};
let service = this.subject({ options });
assert.ok(service);
});

test('it uses clientOptions', function(assert) {
let customDataIdFromObject = o => o.name;
let OverriddenService = ApolloService.extend({
// Need this here because apollo requires a uri, but our initializer doesn't
// run in unit tests.
options: {
apiURL: 'https://this-should-be-set-from-environment.example',
},

this.register('service:overridden-apollo', ApolloService.extend({
// Override the clientOptions.
clientOptions: computed(function() {
let opts = this._super(...arguments);
opts.dataIdFromObject = customDataIdFromObject;
return opts;
}),
});
let service = OverriddenService.create({});
}));
let service = this.container.lookup('service:overridden-apollo')

// make sure the override was used.
assert.equal(service.get('apollo.dataIdFromObject', customDataIdFromObject));
Expand Down

0 comments on commit fdfa804

Please sign in to comment.