How to implement mutations using nreco.graphql in dotnet application - c#

I am very new to Graphql and trying to implement mutations in dotnet using nreco.graphql, as of now there are no errors in the project files , when I tried to execute the mutation query am getting below error message. It says the input format what we are passing is not valid but I verified it many times and there is no error in it. So please help me to resolve the issue.
Query:
mutation($TestValue:TestInput!) {
ActivateInactivateUser(data:$TestValue) {
Status
}
}
Query Variables:
{
"TestValue": {
"UserID": "5",
"UserName": "Test",
"Status": "Inactive"
}
}
Error message:
Variable '$TestValue' is invalid. Unable to parse input as a 'TestInput' type. Did you provide a List or Scalar value accidentally

I am very new to Graphql and trying to implement mutations in dotnet using nreco.graphql, as of now there are no errors in the project file
As far as I know, NReco.GraphQL based on engine Graph.Net. When it comes to mutation queries - you can check the docs from Graph.Net team here
Error message: Variable '$TestValue' is invalid. Unable to parse input as a 'TestInput' type. Did you provide a List or Scalar value accidentally
Did you set up an appropriate model for the method "ActivateInactivateUser"?
You ought to add sth like this:
public class TestInputType : InputObjectGraphType

Related

Devart Error when I return database object with IActionResult

I am trying to return the database object that I get from my service in an IActionResult API Call (c# web API project). Whenever I attempt to do that I get this error:
System.Text.Json.JsonException: A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles.
Here is my API code that is throwing this:
[HttpGet]
[Route("content")]
public IActionResult GetAllContent()
{
try
{
List<Content> allContent = _contentService.GetAll();
return Ok(allContent);
}
catch (Exception ex)
{
//Log something here
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
I could easily mitigate the error by parsing through the content and creating a dynamic object, but I find it annoying to do whenever I want to return a database object when I'm using the Devart Database Context.
Edit:
Further piece of the error message is this:
$.PortalCodeMappings.Content.PortalCodeMappings.Content.PortalCodeMappings.Content.PortalCodeMappings.Content.PortalCodeMappings.Content.PortalCodeMappings.Content.PortalCodeMappings.Content.PortalCodeMappings.Content.PortalCodeMappings.Content.PortalCodeMappings.Content.ContentId.
And I understand the circular reference here, is there a way to tell devart I only want the Content section of this without doing something like this:
allContent.Select(x => new { ... });
Edit: I am using Devart Entity Devloper to generate my models and the dbcontext. I do not use Visual Studio or any IDE.
There are two alternative ways to solve the issue:
Use System.Text.Json (de)serialization
Add JsonIgnoreAttribute to one of the navigation property ends
You can add a custom attribute via the interface of Entity Developer this way:
a) navigate to Model > Settings > Attributes > select the System.Text.Json.dll assembly and make sure that JsonIgnoreAttribute is checked in the window below, press OK
b) select JsonIgnoreAttribute in the Attributes collection of a particular class property

AWS Firehose transform Lambda function throws Lambda.MissingRecordId error for every record

I'm using AWS firehose with an S3 backup and an S3 destination bucket, and it works great. The problem arises when I try to transform the data with a Lambda function.
I'm using the .NET AWS SDK, my Lambda function is written in C# and is using the included firehose transform example:
[assembly:LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.JsonSerializer))]
namespace LambdaFunctions
{
public class Function
{
public KinesisFirehoseResponse FunctionHandler(KinesisFirehoseEvent evnt, ILambdaContext context)
{
context.Logger.LogLine($"InvocationId: {evnt.InvocationId}");
context.Logger.LogLine($"DeliveryStreamArn: {evnt.DeliveryStreamArn}");
context.Logger.LogLine($"Region: {evnt.Region}");
KinesisFirehoseResponse response = new KinesisFirehoseResponse
{
Records = new List<KinesisFirehoseResponse.FirehoseRecord>()
};
foreach (KinesisFirehoseEvent.FirehoseRecord record in evnt.Records)
{
context.Logger.LogLine($"\tRecordId: {record.RecordId}");
context.Logger.LogLine($"\t\tApproximateArrivalEpoch: {record.ApproximateArrivalEpoch}");
context.Logger.LogLine($"\t\tApproximateArrivalTimestamp: {record.ApproximateArrivalTimestamp}");
context.Logger.LogLine($"\t\tData: {record.DecodeData()}");
// Transform data: For example ToUpper the data
KinesisFirehoseResponse.FirehoseRecord transformedRecord = new KinesisFirehoseResponse.FirehoseRecord
{
RecordId = record.RecordId,
Result = KinesisFirehoseResponse.TRANSFORMED_STATE_OK
};
transformedRecord.EncodeData(record.DecodeData().ToUpperInvariant());
response.Records.Add(transformedRecord);
}
return response;
}
}
}
The data is successfully & correctly processed by the transform Lambda function (as indicated by tests & logs).
However, the data is not successfully returned by the Lambda function to the S3 destination bucket, all of the records are unsuccessfully processed.
This error is returned for each record:
{
"attemptsMade": 1,
"arrivalTimestamp": 1590656820209,
"errorCode": "Lambda.MissingRecordId",
"errorMessage": "One or more record Ids were not returned. Ensure that the Lambda function returns all received record Ids.",
"attemptEndingTimestamp": 1590656883464,
"rawData": "dGVzdDE=",
"lambdaArn": "arn:aws:lambda:Region:AccountNumber:function:transform-function:$LATEST"
}
I'm at a loss as to why or where this error is occurring. I know the Lambda function is returning the correct response, recordId included.
I've recreated all the resources, applied and re-applied permissions, done just about everything I can think of.
This issue doesn't happen when using the Node.js or Python versions, it seems to be unique to the .NET implementation.
EDIT:
I forgot to add the serializer assembly attribute to the original code block which ended up being the source of the issue.
The C# example provided by AWS is out of date, specifically this serialization package:
Amazon.Lambda.Serialization.SystemTextJson
To solve this issue, simply replace the package with this one:
Amazon.Lambda.Serialization.Json
and update the assembly attribute like so:
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
namespace LambdaFunctions
{
...
This serialization package is mentioned in the AWS Documentation here, under "Serializing Lambda functions".
However, Amazon have not yet updated the SDK examples to reflect this change (or at least, this example specifically), causing the function to fail when deployed.

How to use a ServiceBus Trigger with a topic/subscription in an Azure Function

I'd like to create an Azure Function that is triggered when a new message is added to a topic/subscription.
For the moment I've created an Azure Function using the ServiceBusQueueTrigger C# Template and I've set the Queue Name to
topicPath + "/Subscriptions/" + subscriptionName
But I've got this exception:
Microsoft.ServiceBus: Cannot get entity 'topic-test/Subscriptions/subscription-test' because it is not of type QueueDescription. Check that you are using method(s) with the correct entity type. System.Runtime.Serialization: Error in line 1 position 1762. Expecting element 'QueueDescription' from namespace 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect'.. Encountered 'None' with name '', namespace ''. .
I thought the Azure Function was using the MessagingFactory.CreateMessageReceiver to initialize the message pump but not.
Is there any support for topic/subscription for the moment ?
Yes topics are supported, but our UI and templates are behind on that unfortunately - we'll be releasing some updates soon addressing these issues.
For now, you can use the Advanced Editor to edit your trigger binding directly. There you can specify your subscriptionName and topicName values. Here's an example:
{
"bindings": [
{
"type": "serviceBusTrigger",
"name": "message",
"direction": "in",
"subscriptionName": "subscription-test",
"topicName": "topic-test",
}
]
}
In general, since Azure Functions is build atop the WebJobs SDK, our various bindings are mapped directly to their SDK counterparts. For example serviceBusTrigger maps to ServiceBusTriggerAttribute which has SubscriptionName/TopicName properties. Therefore, expect to see the same properties in the Function metadata model.

Azure Search SDK Create DataSource

I've been created a datasource by Azure Search SDK.
The Datasource from Azure sql which is a View.
I tyr to setting the DataChangeDetectionPolicy and DataDeletionDetectionPolicy,
but i can't understand how to set this two property.
When i think this two property doesn't supported on the preview sdk,so i try to use REST API to solve this.
I read the article:
MSDN Create Data Source (Azure Search Service REST API)
And use Chrome Extension Postman to set the Data Change Detection Policies.
Url : https://domain.search.windows.net/datasources/temp1?api-version=2015-02-28
body :
{
"#odata.type" : "#Microsoft.Azure.Search.HighWaterMarkChangeDetectionPolicy",
"highWaterMarkColumnName" : "ModifiedDatetime"
}
then i get the 400 bad request .
error message:
{
"error":
{
"code": "",
"message": "The request is invalid. Details: dataSource : Incompatible type kinds were found. The type 'Microsoft.Azure.Search.HighWaterMarkChangeDetectionPolicy' was found to be of kind 'Complex' instead of the expected kind 'Entity'.\r\n"
}
}
So,i have two questions.
1.Is the SDK are not support this function Now?
2.with the REST API , how to solve the error?
Thanks for reply.
Based on the official article, the way to create the datasource for SQL integration for Views is:
{
"name" : "myazuresqldatasource",
"type" : "azuresql",
"credentials" : { "connectionString" : "connection string" },
"container" : { "name" : "table or view name" },
"dataChangeDetectionPolicy" : {
"#odata.type" : "#Microsoft.Azure.Search.HighWaterMarkChangeDetectionPolicy",
"highWaterMarkColumnName" : "[a row version or last_updated column name]"
}
}
The SDK does support data source creation. See https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.search.models.datasource

CRM 2015 SDK : The deserializer has no knowledge of any type that maps to this name

I am currently working with CRM 2015 SDK. I am simply trying to update a value in C# with this SDK. But for some reasons that I try to figure out, there is a trouble when I save my context.
There is the code :
foreach (KeyValuePair<string, Account> account in dicAccount)
{
//Calcul of url/login/date/key/customer values
string generatedUrl = Utilities.GenerateURL(url, login, date, key, customer);
account.Value.new_Link = generatedUrl;
if (!context.IsAttached(account.Value))
{
context.Attach(account.Value);
}
context.UpdateObject(account.Value);
}
SaveChangesResultCollection results = context.SaveChanges(SaveChangesOptions.ContinueOnError);
if (results != null)
{
foreach (SaveChangesResult result in results)
{
Type type = result.Request.GetType();
bool hasError = result.Error != null;
Entity entity = (Entity)result.Request.Parameters["Target"];
if (type == typeof(UpdateRequest))
{
if (hasError)
{
if (entity != null)
{
log.Error(result.Error.Message);
}
}
}
On my Dynamics entities, I have this :
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("new_link")]
public string new_Link
{
get
{
return this.GetAttributeValue<string>("new_link");
}
set
{
this.OnPropertyChanging("new_link");
this.SetAttributeValue("new_link", value);
this.OnPropertyChanged("new_link");
}
}
Right now, I got this error printed by the LogError :
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:request. The InnerException message was 'Error in line 1 position 12271. Element 'http://schemas.datacontract.org/2004/07/System.Collections.Generic:value' contains data from a type that maps to the name 'http://schemas.microsoft.com/xrm/7.1/Contracts:ConcurrencyBehavior'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'ConcurrencyBehavior' and namespace 'http://schemas.microsoft.com/xrm/7.1/Contracts'.'. Please see InnerException for more details.
After few searchs, I found 2 possible causes :
Enable Proxy type : the fact is I have the code to do that. So this couldn't help me.
_serviceProxy.EnableProxyTypes();
Version of SDK : I saw some answers about the fact that the SDK version 7.0 can cause this problem. The fact is that I am using the version 7.1 and I also try with the latest 7.1.1. I use this DLL's : Microsoft.Xrm.Client, Microsoft.Xrm.Sdk, Microsoft.Crm.Sdk.Proxy
Type of this element : I also try with a basic string as datatype. There is still problem of serealization.
None of these ideas solve my problem and right now, I do'nt really know where I am suppose to look into to solve fix this problem.
Also the problem might be unknown types. It's important to enable proxy types on OrganizationServiceProxy. It solved my issue with similar error
using (OrganizationServiceProxy proxy = new OrganizationServiceProxy(organizationUri, null, credentials, null))
{
proxy.EnableProxyTypes();
}
Not 100% what the issue is but I would suggest trying the following to see if it helps.
Regenerate your proxy, it might be a case that your proxy is out of date which is why the deserializer has no knowledge of any type that maps to this name.
Try using late bound just to see if that works, help to narrow things down if there is a problem in the early bound code. For example:
Entity account = new Entity("account");
account.Id = new Guid("");
account["new_link"] = "your value";
service.Update(account);
Break point the code and see what values are being updated on the account objects, e.g. make sure another attribute doesn't have an odd value.
I will share my solution to this problem, when using own created WCF services, which are using generated models from CRM.
When referencing the WCF service in other project using VS 2017, there are some options in the Add Service Reference window: press "Advanced..." and uncheck Reuse types in referenced assemblies
Hope it helps someone.
I have solved this problem by updating the referece Microsoft.Xrm.Tooling.Connector
It turned out that I was using an older version which did not match with others SDK references, but it did not crash when building the program.
You can use NuGet to get that assembly.
This is the project's URL:
https://learn.microsoft.com/es-es/dotnet/api/microsoft.xrm.tooling.connector?view=dynamics-xrmtooling-ce-9

Categories