Closed buschtoens closed 5 years ago
(Having multiple instances of ember-auto-import is supposed to be irrelevant. They will find each other and deduplicate, as long as everybody is resolving the same copy of the dependency. I don't think that is actually your problem here.)
graphql-tools
has a peerDependency on graphql
, which means "if you depend on graphql-tools
, you must also depend directly on graphql
". So for an app to use graphql-tools
, the app must have a dependency on graphql
.
ember-apollo-client
should do the same thing that graphql-tools
does, for the same reason. You should have a peerDependency on graphql
. This is the only reliable way to get one shared copy of graphql
for the whole app and all its libraries.
This is annoying because it means app authors need to be told to install two packages (ember-apollo-client
plus graphql
) instead of one (ember-apollo-client
). You can help a little by doing it for them in a default blueprint. But it's simply not correct in NPM semantics to expect other packages to be able to see one of your dependencies
.
Thanks a lot for the pointer. That makes a lot of sense. I'll give it a go later. :+1:
I have tried to add peerDependencies to the PR mentioned above and it doesn't seem to solve the problem we are seeing.
The thing is, we are seeing this error within ember-apollo-client
, the consumer in this case is the dummy app.
I have a branch in my fork where it is rebased and has the peer deps specified: https://github.com/josemarluedke/ember-apollo-client/tree/jl-ts-with-peer-deps. Check this commit to see relevant changes.
Any other ideas for us to try?
There are multiple layers of issues combining here.
That branch you shared allowed me to reproduce a legit bug in ember-auto-import. We are including graphql in both vendor.js and test-support.js. I filed https://github.com/ef4/ember-auto-import/issues/175 to cover that.
That is probably enough to fix your dummy app, because by definition your dummy app and your addon have the same dependencies.
But it's probably not enough to get what you want in real apps, because you still have graphql
in dependencies
. It needs to not be there. Otherwise you will end up with your own copy that is distinct from the app's copy. Instead you should:
Since the original request in this issue is anti-pattern-ish and the underlying bug that motivated it is tracked in #175, I think we can close this issue.
@ef4 Thanks for the suggested peerDep fix! @josemarluedke Thanks for applying it!
I think we already had an issue about this, but I can't seem to find it.
I am in the process of migrating
ember-apollo-client
to TypeScript and upgrading it to the latest and greatest of all its dependencies and seem to have hit a brick wall. 🚧https://github.com/bgentry/ember-apollo-client/pull/175#issuecomment-448005937:
We cannot force the consumer to import
graphl
from an addon re-export likeember-apollo-client/graphl
, because there might be third-party libraries likegraphql-tools
, that importgraphql
in turn.Do you know a clever way for an addon to "inject" arbitrary imports into the host app or control where the host app is getting its imports from?