Skip to content

Commit

Permalink
feat(graph): add advanced query behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Stanger committed Jun 20, 2024
1 parent 61df3d1 commit 5bfebcd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/graph/behaviors.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')")();
```
14 changes: 14 additions & 0 deletions packages/graph/behaviors/advanced-query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TimelinePipe } from "@pnp/core";
import { Queryable } from "@pnp/queryable";
import { ConsistencyLevel } from "@pnp/graph";

export function AdvancedQuery(): TimelinePipe<Queryable> {

return (instance: Queryable) => {

instance.using(ConsistencyLevel());
instance.query.set("$count", "true");

return instance;
};
}

0 comments on commit 5bfebcd

Please sign in to comment.