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

Example of own resolvers for query / filter involving Union types #75

Open
rgaiacs opened this issue Jan 11, 2024 · 1 comment
Open

Comments

@rgaiacs
Copy link
Contributor

rgaiacs commented Jan 11, 2024

I spent a few hours to figure out how to write my own resolver for query / filter involving Union types.

The solution that works for me was something like

let foos = context.mirageSchema.all('foo').models;
for (let foo of foos) {
  foo.__typename = 'Foo';
}

let bars = context.mirageSchema.all('bar').models;
for (let bar of bars) {
  bar.__typename = 'Bar';
}

return [].concat(foos, bars);

Did I miss something in the documentation?

Should I send a pull request adding this use case to the list of examples?

@jneurock
Copy link
Collaborator

I’m glad you found a solution and I think it’s so nice that you’ve offered to add an example!

I have 2 thoughts:

  1. There aren’t actually any docs; just the README, which is very limited (on purpose). I’d like to publish some real documentation, and an example like yours would be perfect for that. It’s on my TODO list (maybe I should publish something sooner rather than later).
  2. Your approach doesn’t take advantage of one of the functions built into the library, and I’d prefer to expose the documentation for that function instead since it’s designed to make this easier.

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

2 participants