Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: enable retrieval of the entire query #185

Open
antcin opened this issue Oct 15, 2021 · 6 comments
Open

Feature request: enable retrieval of the entire query #185

antcin opened this issue Oct 15, 2021 · 6 comments
Labels
feature-request New feature or request

Comments

@antcin
Copy link

antcin commented Oct 15, 2021

Following conversation with the AWS Support Team, I was advised to open an issue to request the following.

Request
Allow for Appsync to return an entire GraphQL query from the context.

Current state
According to the Info section in the documentation, the $context.info.selectionSetGraphQL value should return the entire query, however it only returns a selection of it.

The Support Team confirmed that there is no supported mechanism to get the entire query today.

Why am I requesting this
I would like to proxy queries from one Appsync endpoint to another.

Refer also to thread in the Discussion Forum for AWS Appsync.

@codymurphyjones
Copy link

codymurphyjones commented Nov 14, 2021

Hey antcin!

So, I'm not sure if they are going to prioritize this at all since the data is actually available, its just overly complicated to access.

I stumbled across a library called ast-to-query.

https://www.npmjs.com/package/graphql-ast-to-query

Unfortunately for me, every time I used this library I had errors (it looked like it was unprocessed tpyescript causing the error).

So I ended up tinkering with that library to resolve the issue.

https://pastebin.com/m89Tm1RG

Here is a variation that is currently workin inside my production environment. I used this to grab the query and then redirect to my graphQL.

I am using a lambda as my parent gateway, alongside apollo-lambda-server the parent gate way is breaking my request into pieces and sending it to the correct graphQL microservice end point.

Here is the "buildQuery" function I am using, you'll notice that astToQuery actually does 100% of the work, and then I do some string modifications to get my desired result.


const buildQuery = (queryData, name) => {
    var query = astToQuery(queryData)

    const strVal = \\s?${name}\\s?{; //Error here because of github code blocks
    const nameGrab = new RegExp(strVal)

    query = query.replace(nameGrab, "")
    query = query.substr(0, query.length - 1)
    return query;
}

buildQuery(info.operation, service.name)

info.operation is what you pass inside of astToQuery

Additionally I wanted to add that $context.info.selectionSetGraphQL is actually only going to give you the query if you are using mapping templates, the documentation only states this within the mapping-templates section and nowhere else.

@jpignata jpignata added the feature-request New feature or request label Nov 24, 2021
@antcin
Copy link
Author

antcin commented Jan 21, 2022

Hey @codymurphyjones!

Sorry for the very late response! Thank you for having found the time to reply to my message, this looks interesting.

I will have take a deeper look at graphql-ast-to-query -and what you've done - and see if the approach fits within my environment (hopefully there'll be a Python package that does something like that!).

@Tenrys
Copy link

Tenrys commented May 15, 2023

2 years later, I cannot find any sign of this operation field inside the info object. Has it been removed?

@PatrykMilewski
Copy link

@Tenrys it's there but you have to extract it manually in resolver from ctx object:

ctx.info.selectionSetList

@Tenrys
Copy link

Tenrys commented Jun 30, 2023

That is only part of the GraphQL request.

@codymurphyjones
Copy link

That is how it is intended to be. You can pass data from your request to your response if you need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants