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

Merged
merged 16 commits into from
Jun 4, 2024
Merged
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
Contributor 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
97 changes: 97 additions & 0 deletions graph/articles/coreTypes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Core Types

## Overview

Types exist in graph which are highly-connected/central to the graph ecosystem. Often, these types are the position of containing many structural properties relevant to other APIs, because they are connected to many entities in the graph.
tylercleveland2 marked this conversation as resolved.
Show resolved Hide resolved

Structural properties should be only added to these core types when they are properties of the entity itself and strictly not for the purpose of convenience due to the entity's position in the graph.
tylercleveland2 marked this conversation as resolved.
Show resolved Hide resolved

## Core Types in 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 type (`user`, `group` or `device`), create a new type that models the information captured in the proposed structural property(s).
tylercleveland2 marked this conversation as resolved.
Show resolved Hide resolved
Then, do one of the following:
- Add a navigation property on the existing type to the new type, containing the new type.
- Contain the new type in an entity set elsewhere, and add a navigation property to the new type on the existing type.
- Contain the new type in an entity set elsewhere, and add a navigation property to the existing type on the new type.

## 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:

Do one of the following:

#### Add a navigation property on the existing type to the new type, containing the new type.
tylercleveland2 marked this conversation as resolved.
Show resolved Hide resolved

Define the new entity type:
```xml
<EntityType name="bankAccountInformation">
tylercleveland2 marked this conversation as resolved.
Show resolved Hide resolved
<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="bankAccountInformation" Type="bankAccountInformation" ContainsTarget="true"/>
</EntityType>
```

#### Contain the new type in an entity set elsewhere, and add a navigation property to the new type on the existing type.
tylercleveland2 marked this conversation as resolved.
Show resolved Hide resolved

Define the new entity type:
```xml
<EntityType name="bankAccountInformation">
<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="bankAccountInformations" EntityType="bankAccountInformation">
```

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

#### Contain the new type in an entity set elsewhere, and add a navigation property to the existing type on the new type.
tylercleveland2 marked this conversation as resolved.
Show resolved Hide resolved

Define the new entity type, with a navigation to the user:
```xml
<EntityType name="bankAccountInformation">
<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">
```