miragejs / graphql

A library for handling GraphQL requests with Mirage JS
MIT License
74 stars 12 forks source link

Make the auto-filtering feature an off-by-default option? #34

Open jneurock opened 3 years ago

jneurock commented 3 years ago

To maintain compatibility with the design of ember-cli-mirage-graphql (the Ember-specific library that came before this), Mirage GraphQL automatically filters records by variables when auto-resolving. I think this behavior is probably surprising to most and I'm not sure if it's actually useful.

Example of the behavior being useful:

query Products($size: String) {
  products(size: $size) {
    id
    name
    size
  }
}

The query is called with a $size variable having the value "XL" and only records that match are returned from Mirage's database.


Example of the behavior being painful (forcing a query to be manually resolved):

query Products($limit: Int) {
  products(limit: $limit) {
    id
    name
  }
}

The query is called with a $limit variable having the value 10 and Mirage GraphQL tries to auto-resolve this by filtering for products having a "limit" field with a value of 10. Since "limit" isn't a field, no records are returned.


I'd like to gather some feedback on whether or not to change this behavior and make it off-by-default. I could add a handler creation option to enable this for anyone who does find this behavior useful.

villander commented 2 years ago

@jneurock it really makes sense I think the @miragejs/graphql should work as graphQL server works out of the box without need for any resolver or custom functions for that.

jneurock commented 1 year ago

I'm planning to make this filtering functionality opt-in for version 0.2.0