Tuesday, 2 May 2017

Is it possible to access specific query variables during a graphQL execution?

Using graphQL, let's say my query is {client(clientId: 1){clientId address DoB}}.

This will return the clientId, address and DoB of the user with a clientId of 1. When defining the function to resolve this query, I query my DB (DynamoDb). When I query dynamo, I can specify which attributes to return. But, as of now, I cannot get graphQL to tell me which attributes the original query contained. Is it possible to access an object that contains the original query variables (clientId, address and DoB), which I can then pass onto the dynamo query? Doing this, obviously, will reduce network load and also make the API more dynamic.

Logic of what is happening now:

Client says to API, return {clientId, address, DoB} -> API says to Dynamo return all attributes of client with specific clientId -> Dynamo returns all attributes -> graphQL API resolves and returns only {clientId, address, DoB}

Logic of what I want to happen:

Client says to API return {clientId, address, DoB} -> API says to Dynamo return {clientId, address, DoB} -> Dynamo returns {clientId, address, DoB} -> graphQL API resolves and returns {clientId, address, DoB}

Let me know if anyone knows if graphQL can do this intrinsically. Otherwise, I'll have to build a wrapper function.



via Collin Pham

No comments:

Post a Comment