👉🏿back to blog series or jump to GitHub repos🧑🏽💻 <<part 2 part4>> |
create a graphql schema for the booking entity from below OData metadata: <?xml version="1.0" encoding="utf-8"?>…
type BOOKING {
TravelID: String!
Description: String
OverallStatus: String
}
input CreatedBooking {
TravelID: ID!
Description: String
OverallStatus: String
}
input UpdatedBooking {
TravelID: ID!
Description: String
OverallStatus: String
}
type Query {
getBooking(TravelID: String!): BOOKING
}
type Mutation {
createBooking(input: CreatedBooking): BOOKING
updateBooking(input: UpdatedBooking): Boolean
}
<!--
Altered version of SAP CSRF policy. Added If-Match header to handle ETags.
-->
<policies>
<inbound>
<base />
<choose>
<!-- CSRF-token only required for every operation other than GET or HEAD -->
<when condition="@(context.Request.Method != "GET" && context.Request.Method != "HEAD")">
<!-- Creating a GET subrequest to get the SAP CSRF token, cookie and ETag. -->
<send-request mode="new" response-variable-name="SAPCSRFToken" timeout="10" ignore-error="false">
<set-url>@(context.Request.Url.ToString())</set-url>
<set-method>GET</set-method>
<set-header name="X-CSRF-Token" exists-action="override">
<value>Fetch</value>
</set-header>
<set-header name="Authorization" exists-action="override">
<value>@(context.Request.Headers.GetValueOrDefault("Authorization"))</value>
</set-header>
</send-request>
<!-- Extract the token and cookie from the "SAPCSRFToken" and set as header in the POST request. -->
<choose>
<when condition="@(((IResponse)context.Variables["SAPCSRFToken"]).StatusCode == 200)">
<set-header name="X-CSRF-Token" exists-action="override">
<value>@(((IResponse)context.Variables["SAPCSRFToken"]).Headers.GetValueOrDefault("x-csrf-token"))</value>
</set-header>
<set-header name="Cookie" exists-action="override">
<value>@{
string rawcookie = ((IResponse)context.Variables["SAPCSRFToken"]).Headers.GetValueOrDefault("Set-Cookie");
string[] cookies = rawcookie.Split(';');
/* new session sends a XSRF cookie */
string xsrftoken = cookies.FirstOrDefault( ss => ss.Contains("sap-XSRF"));
/* existing sessions sends a SessionID. No other cases anticipated at this point. Please create a GitHub Pull-Request if you encounter uncovered settings. */
if(xsrftoken == null){
xsrftoken = cookies.FirstOrDefault( ss => ss.Contains("SAP_SESSIONID"));
}
return xsrftoken.Split(',')[1];}</value>
</set-header>
<!-- add ETag for GraphQL orchestrated calls -->
<set-header name="If-Match" exists-action="override">
<value>@(((IResponse)context.Variables["SAPCSRFToken"]).Headers.GetValueOrDefault("ETag"))</value>
</set-header>
</when>
</choose>
</when>
</choose>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
<find-and-replace from="@(context.Api.ServiceUrl.Host)" to="@(context.Request.OriginalUrl.Host)" />
</outbound>
<on-error />
</policies>
query getBooking ($travelId: String!){
getBooking(TravelID: $travelId) {
Description
OverallStatus
TravelID
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
14 | |
9 | |
7 | |
7 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 |