Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add guidance for types which should not have new structural properties #537

Open
wants to merge 16 commits into
base: vNext
Choose a base branch
from
Open
10 changes: 10 additions & 0 deletions graph/GuidelinesGraph.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Table of contents
- [Query support](#query-support)
- [Behavior modeling](#behavior-modeling)
- [Error handling](#error-handling)
- [Limitations on core types](#limitations-on-core-types)
- [External standards](#external-standards)
- [API contract and nonbackward compatible changes](#api-contract-and-nonbackward-compatible-changes)
- [Versioning and deprecation](#versioning-and-deprecation)
Expand Down Expand Up @@ -332,6 +333,15 @@ For a complete mapping of error codes to HTTP statuses, see

<a name="api-contract-and-non-backward-compatible-changes"></a>

### Limitations on core types
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add this guidance for applications and servicePrincipals too? In my mind those are core types.

We actually now have a very real example of why this is important for downstream tooling. Adding a structural property that is handled by a different workload (from the core workload) is really difficult to model with Bicep. If instead it's added as a new entity + nav property, this fits cleanly with Bicep (and ARM's) nested child resources.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a structural property that is handled by a different workload (from the core workload)

FYI, I think we have a different ADR that says we should stop using composite entities.

I'm ok adding applications and servicePrincipals, but I don't think those have been brought up with the API council. Do we want to take this PR as-is and do a follow-up to add apps and sps after discussion with the council?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am inclined to take Garrett's suggestion. If you are fine with this, I will merge as-is @dkershaw10


The types `user`, `group`, and `device` should not have any new structural property(s) added, without compelling justification.
Instead, model the concept represented in those property(s) as a new entity and do one of the following:
1. Add navigation from `user`, `group`, or `device` to the new entity.
2. Add a navigation from the new entity to `user`, `group` or `device`.

More details and examples are available in [Core types](./articles/coreTypes.md).

## External standards

For ease of client use and interoperatibility, some APIs might implement a standard that is defined external to Microsoft Graph and OData.
Expand Down
94 changes: 94 additions & 0 deletions graph/articles/coreTypes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Core Types

## Overview

Types exist in Microsoft Graph which are highly-connected/central to the Microsoft Graph ecosystem. Often, these types are in the position of being able to contain structural properties relevant to other APIs, because they are connected to many entities in Microsoft Graph.

Structural properties should be only added to these core types when they are intrinsic to the entity itself, and strictly not for the purpose of convenience due to the entity's position in Microsoft Graph.

## Core Types in Microsoft Graph

The following types are identified as core types, and will require strong justification to allow new structural properties to be added in all cases.

- ```user```
- ```group```
- ```device```

## Alternatives to Adding Structural Properties

Instead of adding a structural property to the existing core type (`user`, `group` or `device`), create a new type that models the information captured in the proposed structural property(s).
Then, model the relationship between the existing core type and the new type by adding a navigation property. For information on modeling with navigation properties, see [Navigation Property](../patterns/navigation-property.md).

## Example:

Modeling adding "bank account information", which includes two properties `accountNumber` and `routingNumber`, to entity type ```user```.

### Don't:

Don't add new properties to core types such as `user`.

```xml
<EntityType name="user">
<Property Name="accountNumber" Type="Edm.string"/>
<Property Name="routingNumber" Type="Edm.string"/>
</EntityType>
```

### Do:

Model the information by creating a new type and model the relationship to the existing core type with a navigation property. To determine which option is most appropriate, see [Navigation Property](../patterns/navigation-property.md):

#### Option 1: Add a navigation property on the existing core type to the new type, containing the new type.

Define the new entity type:
```xml
<EntityType name="bankAccountDetail">
<Property Name="accountNumber" Type="Edm.string"/>
<Property Name="routingNumber" Type="Edm.string"/>
</EntityType>
```

Add a contained navigation from user to the new entity type:
```xml
<EntityType name="user">
<NavigationProperty Name="bankAccountDetail" Type="bankAccountDetail" ContainsTarget="true"/>
</EntityType>
```

#### Option 2: Contain the new type in an entity set elsewhere, and add a navigation property to the new type on the existing core type.

Define the new entity type:
```xml
<EntityType name="bankAccountDetail">
<Property Name="accountNumber" Type="Edm.string"/>
<Property Name="routingNumber" Type="Edm.string"/>
</EntityType>
```

Contain the new entity type in an entity set or singleton:
```xml
<EntitySet Name="bankAccountDetails" EntityType="bankAccountDetail">
```

Add a navigation from user to the new type:
```xml
<EntityType name="user">
<NavigationProperty Name="bankAccountDetail" Type="bankAccountDetail" />
</EntityType>
```

#### Option 3: Contain the new type in an entity set elsewhere, and add a navigation property to the existing core type on the new type.

Define the new entity type, with a navigation to the user:
```xml
<EntityType name="bankAccountDetail">
<Property Name="accountNumber" Type="Edm.string"/>
<Property Name="routingNumber" Type="Edm.string"/>
<NavigationProperty Name="user" Type="microsoft.graph.user" />
</EntityType>
```

Contain the new entity type in an entity set or singleton:
```xml
<EntitySet Name="bankAccountInformations" EntityType="bankAccountInformation">
```