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 Support to specifiy ODataQuery Parameters in Microsoft Graph Client #827

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ codeunit 9351 "Graph Client Impl."
GraphUriBuilder: Codeunit "Graph Uri Builder";
begin
Clear(HttpResponseMessage);
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters());
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters(), GraphOptionalParameters.GetODataQueryParameters());
GraphRequestHelper.SetRestClient(RestClient);
HttpResponseMessage := GraphRequestHelper.Get(GraphUriBuilder, GraphOptionalParameters);
exit(HttpResponseMessage.GetIsSuccessStatusCode());
Expand All @@ -63,7 +63,7 @@ codeunit 9351 "Graph Client Impl."
var
GraphUriBuilder: Codeunit "Graph Uri Builder";
begin
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters());
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters(), GraphOptionalParameters.GetODataQueryParameters());
GraphRequestHelper.SetRestClient(RestClient);
HttpResponseMessage := GraphRequestHelper.Post(GraphUriBuilder, GraphOptionalParameters, RequestHttpContent);
exit(HttpResponseMessage.GetIsSuccessStatusCode());
Expand All @@ -73,7 +73,7 @@ codeunit 9351 "Graph Client Impl."
var
GraphUriBuilder: Codeunit "Graph Uri Builder";
begin
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters());
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters(), GraphOptionalParameters.GetODataQueryParameters());
GraphRequestHelper.SetRestClient(RestClient);
HttpResponseMessage := GraphRequestHelper.Patch(GraphUriBuilder, GraphOptionalParameters, RequestHttpContent);
exit(HttpResponseMessage.GetIsSuccessStatusCode());
Expand All @@ -83,7 +83,7 @@ codeunit 9351 "Graph Client Impl."
var
GraphUriBuilder: Codeunit "Graph Uri Builder";
begin
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters());
GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters(), GraphOptionalParameters.GetODataQueryParameters());
GraphRequestHelper.SetRestClient(RestClient);
HttpResponseMessage := GraphRequestHelper.Put(GraphUriBuilder, GraphOptionalParameters, RequestHttpContent);
exit(HttpResponseMessage.GetIsSuccessStatusCode());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace System.Integration.Graph;

/// <summary>
/// A Microsoft Graph API operation might support one or more of the following OData system query options.
/// These query options are compatible with the OData V4 query language and are supported only in GET operations.
/// See: hhttps://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#odata-system-query-options
/// </summary>
enum 9352 "Graph OData Query Parameter"
{
Access = Public;
Extensible = false;

/// <summary>
/// Query Parameter '$count'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#count-parameter
/// </summary>
value(0; count)
{
Caption = '$count', Locked = true;
}

/// <summary>
/// OData Query Parameter '$expand'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#expand-parameter
/// </summary>
value(10; expand)
{
Caption = '$expand', Locked = true;
}


/// <summary>
/// OData Query Parameter '$filter'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#filter-parameter
/// </summary>
value(20; filter)
{
Caption = '$filter', Locked = true;
}

/// <summary>
/// OData Query Parameter '$format'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#format-parameter
/// </summary>
value(30; format)
{
Caption = '$format', Locked = true;
}
/// <summary>
/// OData Query Parameter '$orderBy'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#orderby-parameter
/// </summary>
value(40; orderby)
{
Caption = '$orderby', Locked = true;
}

/// <summary>
/// OData Query Parameter '$search'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#search-parameter
/// </summary>
value(50; search)
{
Caption = '$search', Locked = true;
}

/// <summary>
/// OData Query Parameter '$select'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#select-parameter
/// </summary>
value(60; select)
{
Caption = '$select', Locked = true;
}

/// <summary>
/// OData Query Parameter '$skip'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#skip-parameter
/// </summary>
value(70; skip)
{
Caption = '$skip', Locked = true;
}

/// <summary>
/// OData Query Parameter '$skipToken'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#skiptoken-parameter
/// </summary>
value(80; skiptoken)
{
Caption = '$skiptoken', Locked = true;
}

/// <summary>
/// OData Query Parameter '$top'.
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#top-parameter
/// </summary>
value(90; top)
{
Caption = '$top', Locked = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ codeunit 9353 "Graph Optional Parameters"
InherentEntitlements = X;
InherentPermissions = X;

var
GraphOptionalParametersImpl: Codeunit "Graph Optional Parameters Impl";

#region Headers

/// <summary>
Expand All @@ -21,7 +24,7 @@ codeunit 9353 "Graph Optional Parameters"
/// <param name="Value">Text value specifying the HttpHeader value</param>
procedure SetIfMatch("Value": Text)
begin
SetRequestHeader('IF-Match', "Value");
SetRequestHeader(Enum::"Graph Request Header"::"If-Match", "Value");
end;

/// <summary>
Expand All @@ -30,7 +33,7 @@ codeunit 9353 "Graph Optional Parameters"
/// <param name="Value">Text value specifying the HttpHeader value</param>
procedure SetIfNoneMatchRequestHeader("Value": Text)
begin
SetRequestHeader('If-None-Match', "Value");
SetRequestHeader(Enum::"Graph Request Header"::"If-None-Match", "Value");
end;

/// <summary>
Expand All @@ -39,7 +42,7 @@ codeunit 9353 "Graph Optional Parameters"
/// <param name="Value">Text value specifying the HttpHeader value</param>
procedure SetPreferRequestHeader("Value": Text)
begin
SetRequestHeader('Prefer', "Value");
SetRequestHeader(Enum::"Graph Request Header"::Prefer, "Value");
end;

/// <summary>
Expand All @@ -48,18 +51,22 @@ codeunit 9353 "Graph Optional Parameters"
/// <param name="Value">Text value specifying the HttpHeader value</param>
procedure SetConsistencyLevelRequestHeader("Value": Text)
begin
SetRequestHeader('ConsistencyLevel', "Value");
SetRequestHeader(Enum::"Graph Request Header"::ConsistencyLevel, "Value");
end;

local procedure SetRequestHeader(Header: Text; HeaderValue: Text)
/// <summary>
/// Sets the value for a HttpHeader for a request.
/// </summary>
/// <param name="GraphRequestHeader">The Request Header</param>
/// <param name="HeaderValue">Text value specifying the HttpHeader value</param>
procedure SetRequestHeader(GraphRequestHeader: Enum "Graph Request Header"; HeaderValue: Text)
begin
RequestHeaders.Remove(Header);
RequestHeaders.Add(Header, HeaderValue);
GraphOptionalParametersImpl.SetRequestHeader(GraphRequestHeader, HeaderValue);
end;

internal procedure GetRequestHeaders(): Dictionary of [Text, Text]
begin
exit(RequestHeaders);
exit(GraphOptionalParametersImpl.GetRequestHeaders());
end;

#endregion
Expand All @@ -72,23 +79,32 @@ codeunit 9353 "Graph Optional Parameters"
/// <param name="GraphConflictBehavior">Enum "Graph ConflictBehavior" value specifying the HttpHeader value</param>
procedure SetMicrosftGraphConflictBehavior(GraphConflictBehavior: Enum "Graph ConflictBehavior")
begin
SetQueryParameter('@microsoft.graph.conflictBehavior', Format(GraphConflictBehavior));
GraphOptionalParametersImpl.SetMicrosftGraphConflictBehavior(GraphConflictBehavior);
end;

internal procedure GetQueryParameters(): Dictionary of [Text, Text]
begin
exit(GraphOptionalParametersImpl.GetQueryParameters());
end;
#endregion

local procedure SetQueryParameter(Header: Text; HeaderValue: Text)
#region ODataQueryParameters


/// <summary>
/// Sets the value for an OData Query Parameter
/// see: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#odata-system-query-options
/// </summary>
/// <param name="GraphODataQueryParameter">The OData query parameter</param>
/// <param name="ODataQueryParameterValue">Text value specifying the query parameter</param>
procedure SetODataQueryParameter(GraphODataQueryParameter: Enum "Graph OData Query Parameter"; ODataQueryParameterValue: Text)
begin
QueryParameters.Remove(Header);
QueryParameters.Add(Header, HeaderValue);
GraphOptionalParametersImpl.SetODataQueryParameter(GraphODataQueryParameter, ODataQueryParameterValue);
end;

internal procedure GetQueryParameters(): Dictionary of [Text, Text]
internal procedure GetODataQueryParameters(): Dictionary of [Text, Text]
begin
exit(QueryParameters);
exit(GraphOptionalParametersImpl.GetODataQueryParameters());
end;
#endregion

var
QueryParameters: Dictionary of [Text, Text];
RequestHeaders: Dictionary of [Text, Text];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace System.Integration.Graph;


codeunit 9358 "Graph Optional Parameters Impl"
{
Access = Internal;
InherentEntitlements = X;
InherentPermissions = X;

#region Headers
procedure SetRequestHeader(GraphRequestHeader: Enum "Graph Request Header"; HeaderValue: Text)
begin
SetRequestHeader(Format(GraphRequestHeader), HeaderValue);
end;

local procedure SetRequestHeader(Header: Text; HeaderValue: Text)
begin
RequestHeaders.Remove(Header);
RequestHeaders.Add(Header, HeaderValue);
end;

internal procedure GetRequestHeaders(): Dictionary of [Text, Text]
begin
exit(RequestHeaders);
end;

#endregion

#region Parameters

procedure SetMicrosftGraphConflictBehavior(GraphConflictBehavior: Enum "Graph ConflictBehavior")
begin
SetQueryParameter('@microsoft.graph.conflictBehavior', Format(GraphConflictBehavior));
end;


local procedure SetQueryParameter(Header: Text; HeaderValue: Text)
begin
QueryParameters.Remove(Header);
QueryParameters.Add(Header, HeaderValue);
end;

procedure GetQueryParameters(): Dictionary of [Text, Text]
begin
exit(QueryParameters);
end;
#endregion

#region ODataQueryParameters

procedure SetODataQueryParameter(GraphODataQueryParameter: Enum "Graph OData Query Parameter"; ODataQueryParameterValue: Text)
begin
SetODataQueryParameter(Format(GraphODataQueryParameter), ODataQueryParameterValue);
end;

local procedure SetODataQueryParameter(ODataQueryParameterKey: Text; ODataQueryParameterValue: Text)
begin
ODataQueryParameters.Remove(ODataQueryParameterKey);
ODataQueryParameters.Add(ODataQueryParameterKey, ODataQueryParameterValue);
end;

procedure GetODataQueryParameters(): Dictionary of [Text, Text]
begin
exit(ODataQueryParameters);
end;

#endregion

var
QueryParameters: Dictionary of [Text, Text];
ODataQueryParameters: Dictionary of [Text, Text];
RequestHeaders: Dictionary of [Text, Text];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace System.Integration.Graph;

/// <summary>
/// The supported request header for the Microsoft Graph API
/// </summary>
enum 9353 "Graph Request Header"
{
Access = Public;
Extensible = false;

/// <summary>
/// If-Match Request Header
/// </summary>
value(0; "If-Match")
{
Caption = 'If-Match', Locked = true;
}

/// <summary>
/// If-None-Match Request Header
/// </summary>
value(10; "If-None-Match")
{
Caption = 'If-None-Match', Locked = true;
}

/// <summary>
/// Prefer Request Header
/// </summary>
value(20; Prefer)
{
Caption = 'Prefer', Locked = true;
}

/// <summary>
/// ConsistencyLevel Request Header
/// </summary>
value(30; ConsistencyLevel)
{
Caption = 'ConsistencyLevel', Locked = true;
}
}
Loading
Loading