Skip to content

Commit 27aa5a2

Browse files
authored
Merge pull request #351 from microsoft/op_LRO
graph LRO
2 parents 1929dfe + de5b67d commit 27aa5a2

File tree

11 files changed

+417
-12
lines changed

11 files changed

+417
-12
lines changed

graph/GuidelinesGraph.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Table of contents
1212
- [Uniform Resource Locators (URLs)](#uniform-resource-locators-urls)
1313
- [Query support](#query-support)
1414
- [Resource modeling patterns](#resource-modeling-patterns)
15+
- [Pros and cons](#pros-and-cons)
1516
- [Behavior modeling](#behavior-modeling)
1617
- [Error handling](#error-handling)
1718
- [API contract and non-backward compatible changes](#api-contract-and-non-backward-compatible-changes)
@@ -215,15 +216,15 @@ The three most often used patterns in Microsoft Graph today are type hierarchy,
215216

216217
- **[Facets](./patterns/facets.md)** are represented by a single entity type with common properties and one facet property (of complex type) per variant. The facet properties only have a value when the object represents that variant.
217218

218-
- **Flat bag of properties** is represented by one entity type with all the potential properties plus an additional property to distinguish the variants, often called type. The type property describes the variant and also defines properties that are required or meaningful for the variant given by the type property.
219+
- **[Flat bag of properties](./patterns/flat-bag.md)** is represented by one entity type with all the potential properties plus an additional property to distinguish the variants, often called type. The type property describes the variant and also defines properties that are required or meaningful for the variant given by the type property.
219220

220221
The following table shows a summary of the main qualities for each pattern and can help you select a pattern fit for your use case.
221222

222223
| API qualities\patterns | Properties and behavior described in metadata | Supports combinations of properties and behaviors | Simple query construction |
223224
|-------------------------|-----------------------------------------------|---------------------------------------------------|---------------------------|
224225
| Type hierarchy | yes | no | no |
225226
| Facets | partially | yes | yes |
226-
| Flat | no | no | yes |
227+
| Flat bag | no | no | yes |
227228

228229
#### Pros and cons
229230

@@ -233,13 +234,13 @@ Following are a few pros and cons to decide which pattern to use:
233234

234235
- Introducing new cases in **hierarchy** is relatively isolated (which is why it is so familiar to OOP) and is considered backwards compatible (at least syntactically).
235236

236-
- Introducing new cases/variants in **[facets](./patterns/facets.md)** is straightforward. You need to be careful because it can introduce situations where previously only one of the facets was non-null and now all the old ones are null. This is not unlike adding new subtypes in the **hierarchy** pattern or adding a new type value in the **flat** pattern.
237+
- Introducing new cases/variants in **[facets](./patterns/facets.md)** is straightforward. You need to be careful because it can introduce situations where previously only one of the facets was non-null and now all the old ones are null. This is not unlike adding new subtypes in the **hierarchy** pattern or adding a new type value in the **[flat bag](./patterns/flat-bag.md)** pattern.
237238

238-
- **hierarchy** and **facets** (to a slightly lesser degree) are well-suited for strongly typed client programming languages, whereas **flat** is more familiar to developers of less strongly typed languages.
239+
- **hierarchy** and **facets** (to a slightly lesser degree) are well-suited for strongly typed client programming languages, whereas **flat bag** is more familiar to developers of less strongly typed languages.
239240

240241
- **facets** has the potential to model what is typically associated with multiple inheritance.
241242

242-
- **facets** and **flat** lend to syntactically simpler filter query expression. **hierarchy** is more explicit but requires the cast segments in the filter query.
243+
- **facets** and **flat bag** lend to syntactically simpler filter query expression. **hierarchy** is more explicit but requires the cast segments in the filter query.
243244

244245
- **hierarchy** can be refined by annotating the collections with OData derived type constraints; see [validation vocabulary](https://github.com/oasis-tcs/odata-vocabularies/blob/main/vocabularies/Org.OData.Validation.V1.md). This annotation restricts the values to certain sub-trees of an inheritance **hierarchy**. It makes it very explicit that the collection only contains elements of some of the subtypes and helps to not return objects of a type that are semantically not suitable.
245246

@@ -379,6 +380,8 @@ The guidelines in previous sections are intentionally brief and provide a jump s
379380
| [Dictionary](./patterns/dictionary.md) | Clients can provide an unknown quantity of data elements of the same type. |
380381
| [Evolvable enums](./patterns/evolvable-enums.md) | Extend enumerated types without breaking changes. |
381382
| [Facets](./patterns/facets.md) | Model parent-child relationships. |
383+
| [Flat bag](./patterns/flat-bag.md) | Model variants of the same type. |
384+
| [Long running operations](./patterns/longRunningOperations.md)| Model operations where processing a client request takes a long time. |
382385
| [Modeling subsets](./patterns/subsets.md) | Model collection subsets for All, None, Included, or Excluded criteria. |
383386
| [Namespace](./patterns/namespace.md) | Organize resource definitions into a logical set. |
384387
| [Type hierarchy](./patterns/subtypes.md) | Model `is-a` relationships using subtypes. |

graph/patterns/LRO.gif

17.9 KB
Loading

graph/patterns/RELO.gif

14.8 KB
Loading

graph/patterns/alternate-key.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Declare `mail` and `ssn` as alternate keys on an entity:
153153
}
154154
```
155155
156-
4. Request a resource where the alternate key property does not exist on any resource in the colleciton:
156+
4. Request a resource where the alternate key property does not exist on any resource in the collection:
157157
158158
```http
159159
GET https://graph.microsoft.com/v1.0/users(email='[email protected]')

graph/patterns/change-notification.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Change notification
2+
3+
Microsoft Graph API Design Pattern
4+
5+
*Provide a short description of the pattern.*
6+
7+
8+
## Problem
9+
10+
*Describe the business context relevant for the pattern.*
11+
12+
*Provide a short description of the problem.*
13+
14+
## Solution
15+
16+
*Describe how to implement the solution to solve the problem.*
17+
18+
*Describe related patterns.*
19+
20+
## When to use this pattern
21+
22+
*Describe when and why the solution is applicable and when it might not be.*
23+
24+
## Issues and considerations
25+
26+
*Describe tradeoffs of the solution.*
27+
28+
## Example
29+
30+
*Provide a short example from real life.*

graph/patterns/evolvable-enums.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Microsoft Graph API Design Pattern
44

5-
*The evolvable enum pattern allows API producers to extend enumerated types with new members without breaking API consumers.*
5+
*The evolvable enums pattern allows API producers to extend enumerated types with new members without breaking API consumers.*
66

77
## Problem
88

graph/patterns/facets.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ In this solution, a child variant is identified by the presence of one or more f
1717

1818
## When to use this pattern
1919

20-
The facet pattern is useful when there is a number of variants and they are not mutually exclusive. It also makes it syntactically easier to query resources by using OData $filter expression because it doesn't require casting.
20+
The facets pattern is useful when there is a number of variants and they are not mutually exclusive. It also makes it syntactically easier to query resources by using the OData `$filter` expression because it doesn't require casting.
2121

22-
You can consider related patterns such as [Type hierarchy](./subtypes.md) and Flat bag of properties.
22+
You can consider related patterns such as [type hierarchy](./subtypes.md) and [flat bag of properties](./flat-bag.md).
2323

2424
## Issues and considerations
2525

2626
When introducing a new facet, you need to ensure that the new facet doesn't change the semantic of the model with its implicit constraints.
2727

2828
## Example
2929

30-
The driveItem resource represents a file, folder, image, or other item stored in a drive and is modeled by using entity type with multiple facets.
30+
The driveItem resource represents a file, folder, image, or other item stored in a drive and is modeled by using an entity type with multiple facets.
3131

3232
```XML
3333

@@ -65,7 +65,7 @@ The driveItem resource represents a file, folder, image, or other item stored in
6565
An API request to get all items from a personal OneDrive returns a heterogenous collection with different facets populated. In the following example, there is a folder, a file, and an image in the collection. The image entity has two facets populated: file and image.
6666

6767
```
68-
https://graph.microsoft.com/v1.0/me/drive/root/children
68+
GET https://graph.microsoft.com/v1.0/me/drive/root/children
6969
7070
Response shortened for readability:
7171

graph/patterns/flat-bag.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Flat bag of properties
2+
3+
Microsoft Graph API Design Pattern
4+
5+
*A known pattern in Microsoft Graph is to model multiple variants of a common concept as a single entity type with all potential properties plus an additional property to distinguish the variants.*
6+
7+
## Problem
8+
9+
API designers need to model a small and limited number of variants of a common concept with a concise list of non-overlapping properties and consistent behavior across variants. The designer also wants to simplify query construction.
10+
11+
## Solution
12+
13+
The API designer creates one entity type with all the potential properties plus an additional property to distinguish the variants, often called `variantType`. For each value of `variantType`, some properties are meaningful and others are ignored.
14+
15+
## When to use this pattern
16+
17+
The flat bag pattern is useful when there is a small number of variants with similar behavior, and variants are queried for mostly read-only operations. The pattern also makes it syntactically easier to query resources by using the OData `$filter` expression because it doesn't require casting.
18+
19+
## Issues and considerations
20+
21+
In general, the flat bag pattern is the least recommended modeling choice because it is weakly typed, and it is difficult to semantically verify targeted resource modifications. However, there are circumstances when query simplicity and a limited number of properties might overweight considerations of a more strongly typed approach.
22+
The pattern is not recommended for a large number of variants and properties because the payload becomes sparsely populated.
23+
24+
You can consider related patterns such as [type hierarchy](./subtypes.md) and [facets](./facets.md).
25+
26+
## Example
27+
28+
A good example for flat bag implementation is the recurrencePattern type on [recurrencePattern](https://docs.microsoft.com/graph/api/resources/recurrencepattern).
29+
30+
The recurrencePattern has six variants expressed as six different values of the `type` property (for example: daily, weekly, ...). The key here is that for each of these values, some properties are meaningful and others are ignored (for example: `daysOfWeek` is relevant when `type` is `weekly` but not when it is `daily`).
31+
32+
```
33+
<EnumType Name="recurrencePatternType">
34+
<Member Name="daily" Value="0" />
35+
<Member Name="weekly" Value="1" />
36+
<Member Name="absoluteMonthly" Value="2" />
37+
<Member Name="relativeMonthly" Value="3" />
38+
<Member Name="absoluteYearly" Value="4" />
39+
<Member Name="relativeYearly" Value="5" />
40+
</EnumType>
41+
42+
<ComplexType Name="recurrencePattern" ags:WorkloadIds="Microsoft.Exchange,Microsoft.IdentityGovernance.AccessReviews,Microsoft.IGAELM,Microsoft.PIM.AzureRBAC,Microsoft.Tasks,Microsoft.Teams.Shifts,Microsoft.Todo" ags:PassthroughWorkloadIds="Microsoft.Exchange">
43+
<Property Name="dayOfMonth" Type="Edm.Int32" Nullable="false" />
44+
<Property Name="daysOfWeek" Type="Collection(graph.dayOfWeek)" />
45+
<Property Name="firstDayOfWeek" Type="graph.dayOfWeek" />
46+
<Property Name="index" Type="graph.weekIndex" />
47+
<Property Name="interval" Type="Edm.Int32" Nullable="false" />
48+
<Property Name="month" Type="Edm.Int32" Nullable="false" />
49+
<Property Name="type" Type="graph.recurrencePatternType" />
50+
</ComplexType>
51+
```

0 commit comments

Comments
 (0)