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 25, 2017
1 parent 58f75d2 commit 9e26cb1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 40 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
15 changes: 6 additions & 9 deletions tests/unit/services/apollo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,23 @@ 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.
// Need this here because apollo requires a uri, but our config environment
// isn't set up in unit tests.
options: {
apiURL: 'https://this-should-be-set-from-environment.example',
},
Expand Down

0 comments on commit 9e26cb1

Please sign in to comment.