How can I search strings for certain values?


#1

Or how do I create custom queries in general?

I read this stackoverflow-question but have no idea how to implement it in graphcool …

Thanks


Query on substrings
#2

You can use the built-in filter options for String fields. Let’s say this is your schema:

type Post {
  id: ID!
  text: String!
  title: String!
}

Then you use this query to get all posts that contain GraphQL in their title:

query {
  allPosts(filter: {
    title_contains: "GraphQL"
  }) {
    id
  }
}

Some other possible filters include:

  • title_starts_with
  • title_ends_with

#3

That’s nice (and easy)!
Are there options for writing custom code though?


#4

You can hook into the request pipeline of mutations using functions. A similar feature for fully custom queries and mutations is planned as well. :slight_smile:


#5

This wont work if you want to search with string with small case or upper case