Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mirage models and relationships #26

Open
skarger opened this issue Oct 17, 2019 · 8 comments
Open

Mirage models and relationships #26

skarger opened this issue Oct 17, 2019 · 8 comments

Comments

@skarger
Copy link

skarger commented Oct 17, 2019

I'm using the currently released ember-cli-mirage-graphql version, 0.1.1.

This video guide about ember-cli-mirage-graphql uses Mirage factories, and so does this repo's dummy app.

Mirage also provides the concepts of models and relationships. Specifically, you can define belongsTo and hasMany relationships between models.

  1. Does this package work with those Mirage features?
  2. If so, would it be possible to add an example, maybe to the dummy app, of how to handle a GraphQL query that loads associated models from the Mirage DB?

I tried using Mirage models in my app, but when handling the GraphQL query it seemed to have trouble loading the related models. I'm not sure if I was lacking some necessary configuration or it's just not supported.

By the way, this may be tangentially related to #18.

@jneurock
Copy link
Contributor

My first thought is that the issue is related to #18, as you mentioned. There are some related records in the tests but I think the add-on currently expects them to be associated in a certain way, which isn't very flexible.

Here is an example: https://github.com/kloeckner-i/ember-cli-mirage-graphql/blob/master/tests/acceptance/customer-test.js#L11. Are you able to relate your records like this for the time being?

@skarger
Copy link
Author

skarger commented Oct 17, 2019

@jneurock OK, looks like that example uses the customer and order factories to create a relationship, rather than Mirage hasMany / belongsTo relationships. That will potentially work for me, I'll give it a try.

@dmzza
Copy link
Contributor

dmzza commented Oct 18, 2019

I watched the same video guide. I’ve been trying to get hasMany relationships to work. One-to-one belongsTo relationships work fine. I’m using factories for every model in my default Scenario.

@skarger Have you been able to get a hasMany relationship working in development (not just in tests)?

I’m thinking of adding a default Scenario to the dummy app to see if it works in development.

@skarger
Copy link
Author

skarger commented Oct 18, 2019

@dmzza no, but I haven't tried yet.

@jneurock
Copy link
Contributor

If you'd like, feel free to fork and add a failing test, or add an example to the dummy app that doesn't work, so I can see where the addon is breaking down.

@dmzza
Copy link
Contributor

dmzza commented Oct 20, 2019

After a lot of exploration, I found the most significant cause of the problem for me. I'm transitioning from ember-data to GraphQL, and I didn't want to delete my ember-data models yet. So Mirage was reading my models and that broke all of my hasMany relationships.

To fix that, I added this to config/environment.js:

    ENV['ember-cli-mirage'] = {
      discoverEmberDataModels: false
    };

Now I can keep all of my models so that my typescript still compiles while I make the transition from ember-data to GraphQL.

However, I also found some inconsistent behavior with the way I construct my relationships using factories. I'm still investigating this, and if I can produce the same problem in the sample app, I might open a PR.

@jneurock
Copy link
Contributor

Ah, very interesting. Thanks for the info. Feel free to open a PR. If you think something should be added to the README to help others with the same situation, feel free to add something there, too.

@jneurock
Copy link
Contributor

jneurock commented Jul 5, 2020

This addon will be deprecated in favor of https://github.com/miragejs/graphql which does use Mirage models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants