-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feedback + refinements: ember-cli-mirage-graphql #2
Comments
Thanks, Sam!!! Regarding these questions:
One piece of insight I can provide about the current Ember CLI Mirage GraphQL add-on is that its main export is a higher order function. You pass in your GraphQL schema and a hash of options and it returns a Mirage request handler callback. To me, this means Mirage is already perfect in this area. In other words, the integration point for Mirage and Mirage GraphQL is already there and I don't see a potential
I could be wrong but my suspicion is that we'll discover needs from Mirage's API as we leverage it more to automatically fetch records and deal with relationships. These needs are "ifs", though. It could be that we can already do everything we need to with Mirage as-is.
I created this video that goes through some basic examples: Ember & GraphQL: A Quick Example. There are also examples in the add-on's dummy app. I could see pulling these examples out into formal documentation. The examples are generic enough, I think, to be shown outside of any Ember context. There are plenty more examples to add, too. |
Thanks, Sam! I'll echo a lot of what @jneurock has already said.
Since all GraphQL requests go to a single endpoint, a route handler is already pretty much a perfect integration point. Our integration ends up looking a lot like what import { makeGraphQLMirageHandler } from '@salsify/graphql-client';
import OurSchema from 'our-app/our-schema.graphql';
// Generate a handler once up front to avoid redoing the work
// every time we spin up a new Mirage instance
const graphqlHandler = makeGraphQLMirageHandler(OurSchema, {
// some optional config
});
export default function() {
this.post('/graphql', graphqlHandler);
// ...other routes
};
Nearly everything we wanted API-wise to power this was already available. The only area we had to get a little creative with was introspection of Mirage itself, though it's entirely possible there are public APIs for some things that we missed. As an example, we ended up writing something like this, which may or may not be relying on an implementation detail and would have been super helpful as just a method on function collectionExists(schema, modelName) {
if (!modelName) {
return false;
}
return camelize(pluralize(modelName)) in schema.db;
}
If you want to provide a GraphQL handler as a first-class piece of the miragejs ecosystem, I think that would be totally reasonable and could build pretty easily on the learnings of Since the integration point is already pretty neat, though, I don't think Mirage itself necessarily has to do much. The main gap I see right now is just the lack of a framework-agnostic implementation. You could probably copy/paste our handler into a vanilla npm package and have it 'just work', though, and I suspect the same is true for the implementation in
One thing I realized at some point when working on this was that it doesn't make any use of Mirage's serialization layer at all; it really just relies on Pretender + Mirage's DB/ORM. If you're considering ways to "un-monolith" Mirage, that might point to serialization as something that could make sense as a separate package from the core. |
Ember CLI Mirage GraphQL is the library that's farthest along in terms of streamlining Mirage + GraphQL usage.
I don't have experience with it but several teams do. The author (@jneurock) also has some ideas for improving it (discussed over here).
Wanted to open this issue to have a place for everyone to chat about it.
@miragejs/graphql
lib? (So far miragejs is a "monolith", we don't have any precedent for adapters/plugins.)The text was updated successfully, but these errors were encountered: