diff --git a/docs/graph/behaviors.md b/docs/graph/behaviors.md index cbdbcb670..80366e001 100644 --- a/docs/graph/behaviors.md +++ b/docs/graph/behaviors.md @@ -194,3 +194,18 @@ const graph = graphfi().using(ConsistencyLevel("{level value}")); await graph.users(); ``` + +## AdvancedQuery + +Using this behaviour, you can enable [advanced query capabilities](https://learn.microsoft.com/en-us/graph/aad-advanced-queries?tabs=http) when filtering supported collections. + +This sets the consistency level to eventual and enables the `$count` query parameter. + +```TypeScript +import { graphfi, AdvancedQuery } from "@pnp/graph"; +import "@pnp/graph/users"; + +const graph = graphfi().using(AdvancedQuery()); + +await graph.users.filter("companyName ne null and NOT(companyName eq 'Microsoft')")(); +``` diff --git a/packages/graph/behaviors/advanced-query.ts b/packages/graph/behaviors/advanced-query.ts new file mode 100644 index 000000000..975195e10 --- /dev/null +++ b/packages/graph/behaviors/advanced-query.ts @@ -0,0 +1,14 @@ +import { TimelinePipe } from "@pnp/core"; +import { Queryable } from "@pnp/queryable"; +import { ConsistencyLevel } from "@pnp/graph"; + +export function AdvancedQuery(): TimelinePipe { + + return (instance: Queryable) => { + + instance.using(ConsistencyLevel()); + instance.query.set("$count", "true"); + + return instance; + }; +}