Gaurav Verma
Gaurav Verma

Reputation: 73

Validation error (UnknownType) && Field Undefined in type 'Mutation' -GraphQL mutation

I am using graphQLClient to intigrate graph API. From insomnia its working fine when i am calling from C# code using graphQLClient its throwing error below two errors:

  1. Validation error (UnknownType) : Unknown type 'ClaimIntakeRequest'"
  2. Validation error (FieldUndefined@[createClaimIntake]) : Field 'createClaimIntake' in type 'Mutation' is undefined"

Below is complete code which i am using. I am out of clues here. Can anyone help?

using GraphQL;
using System;
using System.Threading.Tasks;
using GraphQL.Client.Http;
using GraphQL.Client.Serializer.Newtonsoft;
using Newtonsoft.Json;
using System.Net.Http.Headers;
using System.Net.Http;
using optum.aru.cms.mod.api.library.Servicess;
using Object = System.Object;
using System.Data.SqlClient;
using optum.aru.cms.api.library.Logger;
using System.Data;
using System.Diagnostics;
using System.Collections.Generic;

namespace optum.aru.cms.api.library.ICE
{
    public class ICEClaimSerach
    {
        string function = string.Empty;
        string clmAuditNbr = string.Empty;
        string subAduditNbr = string.Empty;
        string site = string.Empty;
        APILogger objAPILog;
        SqlConnection conn;
        readonly string ICE_ClaimSerachURL = string.Empty;
        ICEToken iCEToken = null;
        private Stopwatch stopWatch = new Stopwatch();
        DateTime dtStart = new DateTime();
        public ICEClaimSerach(DataTable dtConfig_Params, SqlConnection connection, string _function, string _clmAuditNbr, string _subAuditNbr, string _site)
        {
           
        }
        public async Task<GraphQLResponse<Object>> CreateClaimIntake( ClaimIntakeRequest 
          requestobj)
        {
            GraphQLResponse<Object> response = null;
            GraphQLRequest query = null;
            GraphQLRequest request = null;
            string response_to_log = string.Empty;
            string ErrorMessage = string.Empty;
            string status = string.Empty;
            var jsonstring = string.Empty;
            try
            {
                ClaimIntakeRequest queryVarivale = requestobj;
                jsonstring = Newtonsoft.Json.JsonConvert.SerializeObject(queryVarivale);
                query = new GraphQLRequest
                {
                    Query = @"mutation 
                   createClaimIntake($claimIntakeRequest4:ClaimIntakeRequest!)
                             {
                               createClaimIntake(claimIntakeRequest:$claimIntakeRequest4)
                               {    
                                    outputMetaData{
                                     consumingAppId        
                                     correlationId
                                     internalCorrelationId
                                     responseMessage
                                   }      
                               }
                             }
                 ",
                    Variables = queryVarivale

                };
                request = new GraphQLRequest(query);
                GraphQLHttpClientOptions graphQLHttpClientOptions = new 
                GraphQLHttpClientOptions
                {
                    EndPoint = new Uri(ICE_ClaimSerachURL, UriKind.Absolute)
                };
                string jwtToken = iCEToken.GetOAuthToken();
                var httpClient = new HttpClient();
                httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + jwtToken);
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));//ACCEPT header
                var graphQLClient = new GraphQLHttpClient(graphQLHttpClientOptions, new NewtonsoftJsonSerializer(), httpClient);
                Console.WriteLine("ICE API started");
                response = await graphQLClient.SendQueryAsync<Object>(request);
                response_to_log = Newtonsoft.Json.JsonConvert.SerializeObject(response);
                Console.WriteLine("ICE API Successfull");
                status = "Success";
                return response;
            }
            catch (GraphQL.Client.Http.GraphQLHttpRequestException ex)
            {
                response_to_log = ex.Message;
                ErrorMessage = ex.Message;
                string stack = ex.StackTrace;
                status = "Failed";
            }
            catch (Exception ex)
            {
                response_to_log = ex.Message;
                ErrorMessage = ex.Message;
                string stack = ex.StackTrace;
                status = "Failed";
            }
            finally
            {
                stopWatch.Stop();
                objAPILog.InsertCPALog("ICEClaimSerach", "POST", clmAuditNbr, subAduditNbr, site, function, dtStart,
                    System.DateTime.Now, stopWatch.ElapsedMilliseconds, ErrorMessage, jsonstring, response_to_log);
            }
            return response;
        }
        public Data_ GetRowData(ClaimIntakeRequest request)
        {

            var response = CreateClaimIntake(request);
            response.Wait();
            var d = response.Result.Data.ToString();
            Data_ ObjCommonResponse = JsonConvert.DeserializeObject<Data_>(d);
            return ObjCommonResponse;
        }
        private void ResetStopWatch()
        {
            dtStart = System.DateTime.Now;
            stopWatch.Reset();
            stopWatch.Start();
        }
    }

    [JsonObject("ClaimIntakeRequest")]
    public class ClaimIntakeRequest
    {
        public claimIntakeRequest4 claimIntakeRequest4 { get; set; }
    }
    public class claimIntakeRequest4
    {
        public Claimintakeinputmetadata claimIntakeInputMetaData { get; set; }
        public List<Claimheadersegment> claimHeaderSegments { get; set; }
    }
    public class Claimintakeinputmetadata
    {
        public string claimSource { get; set; }
        public string claimReferenceNbr { get; set; }
    }
    public class Claimheadersegment
    {
        public Patientsegment patientSegment { get; set; }
        public Claimsegment claimSegment { get; set; }
        public List<Servicelinesegment> serviceLineSegments { get; set; }
        public Billingprovidersegment billingProviderSegment { get; set; }
        public List<Otherprovidersegment> otherProviderSegments { get; set; }
    }
    public class Patientsegment
    {
        public string patientDateOfBirth { get; set; }
        public string cardholderId { get; set; }
        public string patientId { get; set; }
        public string patientFirstName { get; set; }
        public string patientLastName { get; set; }
        public string patientGenderCode { get; set; }
    }

    public class Claimsegment
    {
        public string payerId { get; set; }
        public string payerName { get; set; }
        public string patientClaimControlNbr { get; set; }
        public int claimFrequencyTypeCode { get; set; }
    }

    public class Billingprovidersegment
    {
        public string entityTypeQlfr { get; set; }
        public string providerNPI { get; set; }
        public string providerTin { get; set; }
        public string providerPhoneNbr { get; set; }
        public string addressLine1 { get; set; }
        public string city { get; set; }
        public string state { get; set; }
        public string postalCode { get; set; }
    }

    public class Servicelinesegment
    {
        public string productServiceIdQualifier { get; set; }
        public string productServiceId { get; set; }
        public string[] procedureModifierCodes { get; set; }
        public double lineChargeAmount { get; set; }
        public int serviceUnitCount { get; set; }
        public double ndcCount { get; set; }
        public string unitOfMeasure { get; set; }
        public string placeOfService { get; set; }
        public string dateOfServiceFrom { get; set; }
        public string dateOfServiceThru { get; set; }
        public string providerClaimNbr { get; set; }
    }

    public class Otherprovidersegment
    {
    }
    public class Response
    {
        public Data_ data { get; set; }
    }

    [JsonObject("Data")]
    public class Data_
    {
        [JsonProperty("createClaimIntake")]
        public Createclaimintake createClaimIntake { get; set; }
    }
    public class Createclaimintake
    {
        [JsonProperty("Outputmetadata")]
        public Outputmetadata_ outputMetaData { get; set; }
    }

    public class Outputmetadata_
    {
        public string consumingAppId { get; set; }
        public string correlationId { get; set; }
        public object internalCorrelationId { get; set; }
        public string responseMessage { get; set; }
    }
}

I tried changing the name of type but nothing works.

Upvotes: 0

Views: 22

Answers (0)

Related Questions