Glory Raj
Glory Raj

Reputation: 17701

Trying to pass parameter with graph ql query getting an error

I have below graphl api query that i am using to send the data from react front app with the object to get the desired results

    {
  allSectionRequests(data:{
    requestStageName:"Request Submitted"
  }){
    section
    type
   }
 }

and then i am trying to pass variable from react like below

     export const GET_SECTIONREQUESTS = gql`
query AllSectionRequests($data: sectionRequestParamsInput){
    allSectionRequests(data: $data){
    section
    type       
  }
 }
`;

I have attached the image that i need to send to graphql api below

enter image description here

and the below is the react code that i will be calling query inside component and then passing data object to graphql api

  const { data: dashBoardData, loading: dashBoardDataLoading, error: dashBoardDataError } = useQuery(GET_SECTIONREQUESTS, {
variables: { data: { requestStageName: 'Request Submitted' } },
});

I am getting error like this below

The variable **data** type is not compatible with the type of the argument **data**.
↵Expected type: SectionRequestParamsInput.

i am not sure where i am doing wrong with this code, could any one please help on this one .

Many thanks

Upvotes: 1

Views: 2077

Answers (1)

Glory Raj
Glory Raj

Reputation: 17701

I have rectified my problem with the below solution

 export const GET_SECTIONREQUESTS = gql`
   query AllSectionRequests($sectionRequestParamsInput: SectionRequestParamsInput){
    allSectionRequests(data: $sectionRequestParamsInput){
    id
    section
    type
    createdBy
    description
    status
    age    
  }
 }
`;

and then changed my input parameters in react like this

 const { data: dashBoardData, loading: dashBoardDataLoading, error: dashBoardDataError } = useQuery(GET_SECTIONREQUESTS, {
variables: { sectionRequestParamsInput: { requestStageName: 'Request Submitted' } },
});

i hope this will helps to any person who is looking for graphql api query with parameters passed in.

Upvotes: 1

Related Questions