Skip to content

Instantly share code, notes, and snippets.

@owenallenaz
Last active April 26, 2019 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owenallenaz/48335a5c6a9165b50c2720a295a26c41 to your computer and use it in GitHub Desktop.
Save owenallenaz/48335a5c6a9165b50c2720a295a26c41 to your computer and use it in GitHub Desktop.
Advanced Filtering

Currently our graphql filters only support exact matches { acct_id : "5" }, or { name : "x" }.

I'm adding the feature to expose mongodb advanced filtering mechanics $exists, $gt, $lt, $regex etc. What should the syntax be for adding advanced filters in a way that we can add them to all of our find() endpoints.

standard filtering in graphql and prefix

{
  auth {
    products(filter: { url : "http://url.is/exactly/this" })
  }
}
graphServer.auth.products({ filter : { url : "http://url.is/exactly/this" } })

expose advanced filter on the "auth_advanced" key

{
  auth {
    // url exists, under the consistent key of auth_advanced so we can re-use across endpoints
    products(filter: { auth_advanced : { url : { exists : true } } })
  }
}
graphServer.auth.products({ filter : { auth_advanced : { url : { exists : true } } } })

expose advanced filter on the "advanced" key. Will we ever want "advanced" to be a column in the db, if so, we'd collide.

{
  auth {
    // url exists, under the consistent key of auth_advanced so we can re-use across endpoints
    products(filter: { advanced : { url : { exists : true } } })
  }
}
graphServer.auth.products({ filter : { advanced : { url : { exists : true } } })

put advanced filter on a separate top-level key

{
  auth {
    products(filter : { someFilter : "foo" }, advanced_filter : { url : { exists : true } })
  }
}
graphServer.auth.products({ filter : { someFilter : "foo" }, advanced_filter : { url : { exists : true } })

Utilize a scalar to process the filter

{
  auth {
    products(filter : { foo : "foo", bar : { exists : true } })
  }
}
graphServer.auth.products({ filter : { foo : "foo", bar : { exists : true } } })

The downside of the scalar is that we lose the ability to "validate" the content of the filter client-side since when it hits a scalar it validates server side. So there is no type-hinting suggestions in the graphql playground. In example if you did { foo : { bogus : "something" } } it won't syntax highlight it as being incorrect. https://www.screencast.com/t/q1jqesXYjIqU

Some other option/combination/naming scheme?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment