Querying - PixelaGt/flusmic GitHub Wiki

Querying

Flusmic uses the Predicate query browser to make all the requests.

This is how a simple query looks like:

final response = await flusmic
    .query([Predicate.at(DefaultPredicatePath.type, 'value')]);

Predicates

You can add as many predicates as you need in a single query call.

final response = await flusmic
    .query([Predicate.at(DefaultPredicatePath.type, 'value'),
        Predicate.at(DefaultPredicatePath.id, 'value')]);

Available predicates

Query
  • Any
  • At
  • FullText
  • Geopoint.Near
  • GreaterThan
  • Has
  • In (into)
  • InRange
  • LessThan
  • Missing
  • Not
  • Similar
Date and time
  • After
  • Before
  • Between
  • Day-of-month
  • Day-of-month After
  • Day-of-month Before
  • Day-of-week
  • Day-of-week After
  • Day-of-week Before
  • Month
  • Month After
  • Month Before
  • Year
  • Hour
  • Hour After
  • Hour Before

Predicate Paths

You need to declare a Predicate Path to tell Flusmic what type of Predicate you are using. There are two type:

DefaultPredicatePath
  • Document: A Predicate to search by document
  • Id: A predicate to search by document ID
  • Tags: A predicate to search by tags in a document
  • Type: A predicate to search by type in a document
  • FirstPublicationDate: A predicate to search by created_at.
  • LastPublicationDate: A predicate to search by updated_at.
CustomPredicatePath
final response = await flusmic
    .query([Predicate.at(CustomPredicatePath('custom-type', 'field'), 'value', fetch: false)]); 

If you will use a CustomPredicatePath with fetch o fetchLink query search, 'fetch' param must be true.

More info about how Predicates works in prismic.io query predicates API reference.

Graph Querying

Prismic.io has a way to work with GraphQL-like syntax called GraphQuery. We can make a request using the graphQuery() method. You can spect a FlusmicResponse after that:

final query = '''
  {
    test {
      title
    }
  }
  ''';
final graphResponse = await flusmic.graphQuery(query);

If you want to know more about it, check Prismic reference for GraphQuery