Skip to content

Latest commit

 

History

History
241 lines (173 loc) · 6.79 KB

query-usage.md

File metadata and controls

241 lines (173 loc) · 6.79 KB

Query Usage

Arguments

The arguments supported are ids, where, orderBy , skip, and take.

Arguments are executed in that order.

Ids

Queries entities by id. Currently the only supported identity member (property or field) name is Id.

Supported Types

String, Guid, Double, Boolean, Float, Byte, DateTime, DateTimeOffset, Decimal, Int16, Int32, Int64, UInt16, UInt32, and UInt64.

Single

{
  entities (ids: "1")
  {
    property
  }
}

Multiple

{
  entities (ids: ["1", "2"])
  {
    property
  }
}

Where

Where statements are and'ed together and executed in order.

Property Path

All where statements require a path. This is a full path to a, possible nested, property. Eg a property at the root level could be Address, while a nested property could be Address.Street. No null checking of nested values is done.

Supported Types

String, Guid, Double, Boolean, Float, Byte, DateTime, DateTimeOffset, Decimal, Int16, Int32, Int64, UInt16, UInt32, UInt64, and Enum.

Supported Comparisons

  • equal (the default value if comparison is omitted)
  • notEqual
  • greaterThan
  • greaterThanOrEqual
  • lessThan
  • lessThanOrEqual:
  • contains: Only works with string
  • startsWith: Only works with string
  • endsWith: Only works with string
  • in: Check if a member existing in a given collection of values
  • notIn: Check if a member doesn't exist in a given collection of values
  • like: Performs a SQL Like by using EF.Functions.Like

Case of comparison names are ignored. So, for example, EndsWith, endsWith, and endswith are allowed.

Single

Single where statements can be expressed:

{
  entities
  (where: {
    path: "Property",
    comparison: "equal",
    value: "the value"})
  {
    property
  }
}

Multiple

Multiple where statements can be expressed:

{
  entities
  (where:
    [
      {path: "Property", comparison: "startsWith", value: "Valu"}
      {path: "Property", comparison: "endsWith", value: "ue"}
    ]
  )
  {
    property
  }
}

Where In

{
  testEntities
  (where: {
    path: "Property",
    comparison: "in",
    value: ["Value1", "Value2"]})
  {
    property
  }
}

Case Sensitivity

All string comparisons are, by default, done using no StringComparison. A custom StringComparison can be used via the case attribute.

{
  entities
  (where: {
    path: "Property",
    comparison: "endsWith",
    value: "the value",
    case: "Ordinal"})
  {
    property
  }
}

Note that many Database Providers, including SQL Server, cannot correctly convert a case insensitive comparison to a server side query. Hence this will result in the query being resolved client side. If this is a concern it is recommended to Disabling client evaluation.

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    optionsBuilder.ConfigureWarnings(
        warnings =>
        {
            warnings.Throw(RelationalEventId.QueryClientEvaluationWarning);
        });
}

snippet source

Null

Null can be expressed by omitting the value:

{
  entities
  (where: {path: "Property", comparison: "equal"})
  {
    property
  }
}

OrderBy

Ascending

{
  entities (orderBy: {path: "Property"})
  {
    property
  }
}

Descending

{
  entities (orderBy: {path: "Property", descending: true})
  {
    property
  }
}

Take

Queryable.Take or Enumerable.Take can be used as follows:

{
  entities (take: 1)
  {
    property
  }
}

Skip

Queryable.Skip or Enumerable.Skip can be used as follows:

{
  entities (skip: 1)
  {
    property
  }
}