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

Question Regarding the Capabilities of graphql-go-tools #1005

Open
luca147 opened this issue Dec 3, 2024 · 2 comments
Open

Question Regarding the Capabilities of graphql-go-tools #1005

luca147 opened this issue Dec 3, 2024 · 2 comments
Assignees
Labels
internally-reviewed Internally reviewed

Comments

@luca147
Copy link

luca147 commented Dec 3, 2024

I've been looking through the documentation and searching online on my own, but I haven't been able to find an example or anything similar.

What I'm trying to achieve with this tool is to create a gateway between our clients (servers) and a supergraph exposed via the Apollo Router. We need to intercept the queries made to this supergraph to:

  • Add specific fields to the query
  • Modify the values of certain fields
  • Change the structure of the response to simplify it

I'm not sure if this is possible with the current setup or if the best approach would be to expose a new GraphQL server with the supergraph as the provider.

Thanks in advance! Any help or suggestions are welcome.

@Noroth Noroth added the internally-reviewed Internally reviewed label Dec 17, 2024
@phob0s-pl
Copy link
Contributor

phob0s-pl commented Dec 19, 2024

Hi!
I am doing similar stuff in my project. I have graphql gateway and service which modifies request before passing it to gateway. The graphql-go-tools is correct tool for such a scenario.
If you take a look at example of gateway in the repository:

  • get request and unmarshall JSON
  • use astparser.ParseGraphqlDocumentString to get ast.Document
  • use astvisitor.Walker to go through query and mutate it, you can take a look how astnormalizer works or astvalidation. They are really cool examples
  • forward modified query to graphql-go-tools engine

Regarding modifying response I will not help you because we do not do this. My feeling is that you'd need to implement it on your own.

@devsergiy
Copy link
Member

Hi @luca147

In addition to @phob0s-pl answer, the execution package has a proxy mode that will allow you to have a single datasource and use the engine for the validation goals

For modifying something you could use custom HTTP transport with roundtripper

This example should give you initial knowledge on how to use validation, normalization, and other things

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internally-reviewed Internally reviewed
Projects
None yet
Development

No branches or pull requests

4 participants