Skip to content

Commit

Permalink
add some default options for test envs
Browse files Browse the repository at this point in the history
Fixes #55.
  • Loading branch information
bgentry committed Oct 4, 2017
1 parent 178dbb7 commit 686526d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions addon/services/apollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,25 @@ function newDataFunc(observable, resultKey, resolve) {
};
}

// used in environments without injected `config:environment` (i.e. unit tests):
const defaultOptions = {
apiURL: "http://testserver.example/v1/graph",
};

export default Service.extend({
client: null,
apiURL: alias('options.apiURL'),

// options are configured in your environment.js.
options: computed(function() {
const config = getOwner(this).resolveRegistration('config:environment');
return config.apollo;
// config:environment not injected into tests, so try to handle that gracefully.
let config = getOwner(this).resolveRegistration("config:environment");
if (config && config.apollo) {
return config.apollo;
} else if (testing) {
return defaultOptions;
}
throw new Error("no Apollo service options defined");
}),

init() {
Expand Down

0 comments on commit 686526d

Please sign in to comment.