Skip to content

Add response log under tmp/codegen when JSON parsing failed #1096

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

Closed
wants to merge 1 commit into from

Conversation

amkisko
Copy link

@amkisko amkisko commented May 8, 2025

Hey!

Here's suggestion on improving logging experience for error, server response might have HTML response or anything else what is not possible to read in console and requires accessing with editor.

I would like to participate in the discussion how to make it better, do we need a configuration variable here for debugging purposes only so that it does not create files without conditionals.

Thank you!

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@enisdenjo
Copy link
Member

Currently there work being done in #1030 which will significantly improve the logging experience in the gateway. Your opinion there would be helpful instead.

What you did here does not really work for us, the gateway's transports are expected to run in all JS enviornments - including those that dont have access to the filesystem - like Cloudlflare Workers and other edge lambdas; meaning, writing files is a no-go.

Instead, you can write a plugin using the onFetch hook returning a function which is an onFetchDone hooks to inspect the result, something roughly like this:

import { defineConfig } from '@graphql-hive/gateway';
import fs from 'node:fs/promises';

export const gatewayConfig = defineConfig({
  plugins: () => [
    {
      onFetch() {
        return async ({ response }) => {
          if (!response.ok) {
            // write the response body to a file when response is failing
            const content = await response.text();
            await fs.writeFile('./somewhere.txt', content);
          }
        };
      },
    },
  ],
});

@enisdenjo enisdenjo closed this May 12, 2025
@amkisko amkisko deleted the patch-1 branch May 12, 2025 15:02
@amkisko
Copy link
Author

amkisko commented May 12, 2025

@enisdenjo thanks for detailed explanation, I was not aware about onFetch and have not seen its usage in the code much, need to assess it, seems to be exact thing I need for temporary hook.

@amkisko
Copy link
Author

amkisko commented May 12, 2025

I think the main problem will be to somehow patch gateway usage in graphql-codegen library in order to get closer to this. :)

@enisdenjo
Copy link
Member

What do you mean by that? How do you use graphql-codegen with the gateway, do you have reproduction we can look at?

@enisdenjo
Copy link
Member

Ah ok, so you're actually talking about the http executor in graphql-codegen, not the gateway. I got confused for a moment.

@amkisko
Copy link
Author

amkisko commented May 13, 2025

Yes, that's correct.

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

Successfully merging this pull request may close these issues.

None yet

2 participants