How to enable multiple query arguments in a synthetic GraphQL API

Ashwin Kumar Sri Vangipuram 1 Reputation point
2023-06-22T04:36:26.5166667+00:00

I'm using Azure API management Synthetic GraphQL feature to transform a normal REST API into GraphQL one.

Let me explain the use case with example mentioned in Microsoft Learning HUB.

I have added a third query getBlogByOwnerAndTitle to existing two(already discussed in the learning hub).I want to be able to filter and return blogs based on owner and title both. I have tried making it a composite filter object and resolve it using set-graphql-resolver policy.But its not working.What I really want is to be able to filter using not just one attribute but more than one.

Thanks,Ashwin

type Comment {
    id: ID!
    owner: string!
    content: string!
}

type Blog {
    id: ID!
    title: string!
    content: string!
    comments: [Comment]!
    comment(id: ID!): Comment
}

type Query {
    getBlog(): [Blog]!
    getBlog(id: ID!): Blog
	getBlogByOwnerAndTitle(owner: string, title: string): [Blog]
}


Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,447 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. MuthuKumaranMurugaachari-MSFT 22,441 Reputation points Moderator
    2023-06-27T18:29:54.47+00:00

    Ashwin Kumar Sri Vangipuram Thanks for posting your question in Microsoft Q&A. set-graphql-resolver policy is retired and as described in the doc, you can add managed resolvers such as HTTP-based data source for GraphQL field in the schema. If you are looking to resolve getBlogByOwnerAndTitle, then owner and title are available as Arguments in context.GraphQL like described in the doc.

    User's image

    Here is code snippet of the resolver policy:

    <http-data-source>
    	<http-request>
    		<set-method>GET</set-method>
    		<set-url>https://data.contoso.com/api/ownertitle</set-url>
    		<set-header name="Content-Type" exists-action="override">
    			<value>application/json</value>
    		</set-header>
    		<set-body>@{ 
                            JObject jsonObject = new JObject();
                            jsonObject.Add("owner", context.GraphQL.Arguments["owner"]);
                            jsonObject.Add("title", context.GraphQL.Arguments["title"]);
                            return jsonObject.ToString();
            }</set-body>
    	</http-request>
    </http-data-source>
    

    Note: this is just for reference, and I didn't have HTTP endpoint to fully validate. I hope this helps and if you face any issues, let me know.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.