You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[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,
215
216
216
217
-**[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.
217
218
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.
219
220
220
221
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.
221
222
222
223
| API qualities\patterns | Properties and behavior described in metadata | Supports combinations of properties and behaviors | Simple query construction |
@@ -233,13 +234,13 @@ Following are a few pros and cons to decide which pattern to use:
233
234
234
235
- 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).
235
236
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.
237
238
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.
239
240
240
241
-**facets** has the potential to model what is typically associated with multiple inheritance.
241
242
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.
243
244
244
245
-**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.
245
246
@@ -379,6 +380,8 @@ The guidelines in previous sections are intentionally brief and provide a jump s
379
380
|[Dictionary](./patterns/dictionary.md)| Clients can provide an unknown quantity of data elements of the same type. |
380
381
|[Evolvable enums](./patterns/evolvable-enums.md)| Extend enumerated types without breaking changes. |
381
382
|[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. |
382
385
|[Modeling subsets](./patterns/subsets.md)| Model collection subsets for All, None, Included, or Excluded criteria. |
383
386
|[Namespace](./patterns/namespace.md)| Organize resource definitions into a logical set. |
384
387
|[Type hierarchy](./patterns/subtypes.md)| Model `is-a` relationships using subtypes. |
Copy file name to clipboardExpand all lines: graph/patterns/facets.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,17 +17,17 @@ In this solution, a child variant is identified by the presence of one or more f
17
17
18
18
## When to use this pattern
19
19
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.
21
21
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).
23
23
24
24
## Issues and considerations
25
25
26
26
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.
27
27
28
28
## Example
29
29
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.
31
31
32
32
```XML
33
33
@@ -65,7 +65,7 @@ The driveItem resource represents a file, folder, image, or other item stored in
65
65
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.
*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`).
0 commit comments