A POC to how to create a filter in a graphql query to search for generic values in mongodb
- @entria/graphql-mongo-helpers
- mongoose
- express
- express-graphql
- graphql
- mongodb
- search
- agregatte
- pipeline
Clone the project
git clone https://github.com/vinibgoulart/gpql-mongo-search.git
Go to the project directory
cd gpql-mongo-search
Install dependencies
yarn
Copy envs
yarn env
Run seeder
yarn seed
Start the server
yarn dev
After that you can open graphql playground in your browser
http://localhost:4000/graphql/playground
Some examples of queries to test the search
Return all products:
query {
products {
name
description
price
}
}
Return a product filtering by name:
query {
products(filters: {search: "Cell"}) {
name
description
price
}
}
Return a product filtering by description:
query {
products(filters: {search: "Apple"}) {
name
description
price
}
}