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

'sendVariablesValues.exceptNames' reporting option GraphQL input fields is not working #5059

Closed
c4c1us opened this issue Mar 25, 2021 · 6 comments

Comments

@c4c1us
Copy link

c4c1us commented Mar 25, 2021

Hi,

First of all, Apollo is great, big fan !

But I'm having an issue regarding the sendVariablesValues.exceptNames options of the report engine. The option works well on query parameters but not on GraphQL Input fields.

I'm using apollo-server and @apollo/gateway, the code below is from my gateway and the query is implemented in one of my services.

Dependencies

"apollo-server": "^2.21.2"

Code

const server = new ApolloServer({
    gateway,
    engine: {
            apiKey: APOLLO_KEY,
            sendVariableValues: {
              exceptNames: ["biography"]
            }
          },
   ...
});

Query

mutation userUpdateProfile($input: UserUpdateProfileInput!) {
  userUpdateProfile(input: $input) {
    biography
  }
}

Schema

...
input UserUpdateProfileInput {
  ...
  biography: String
  ...  
}

Actual Behaviour

Operation trace on Apollo Studio

Screenshot 2021-03-25 at 17 12 09

Expected Behaviour

{
  "input":{}
}
@glasser
Copy link
Member

glasser commented Mar 25, 2021

The name of your variable is input.

biography is not a variable name: it's an input field name.

I do agree that wanting to filter based on input field names is reasonable, but it's not directly supported by the API. You can implement it yourself with the transform option. One of our internal servers actually does that. At the very least it would be a nice thing to add to the examples in the docs, or as a separate package that people can import to generate transform functions (perhaps not actually part of the Apollo Server project).

I'm closing this because this isn't a bug: the code implements what it's intended to. That said, I'd be excited to see community contributions of helpful transform functions; most likely this would be most useful as a third-party package we can recommend or as a doc change, rather than hard-coding logic into the API that's more complex than "just look at the list of variable names".

@glasser glasser closed this as completed Mar 25, 2021
@c4c1us
Copy link
Author

c4c1us commented Mar 25, 2021

Hi,

Thanks for your reply, okay I understand it's not a bug.

I tried to use the transform option. Unfortunately when I used it, the data sent from the gateway to my services is transformed too.

Code

Screenshot 2021-03-25 at 20 19 24

Playground

Screenshot 2021-03-25 at 20 23 40

@c4c1us
Copy link
Author

c4c1us commented Mar 25, 2021

Maybe I should create an issue on the @apollo/gateway repository @glasser ?

@glasser
Copy link
Member

glasser commented Mar 25, 2021

Oof, that is surprising. I don't think it's specific to the gateway, though.

Specifically, what's going on is that you're mutating stuff nested under the variables argument in your transform callback. This happens to be the same value used internally to actually execute the query (whether via gateway or direct execution).

I'm not sure of the best thing to do here. We can always do some sort of deep clone operation on variables before passing to the callback, but that can have a performance impact, and if you somehow have something in your variables that isn't easily cloneable (not sure how likely this is) then that can cause its own problems. Another alternative would be to just more clearly document that the transform operation should regard variables as read-only (perhaps in TypeScript using something like the workarounds at microsoft/TypeScript#13923)

For your own code, you can change the assignment line to:

variables.input = {...variables.input, biography: "HIDDEN"};

(It's OK to mutate fields on variables itself because you've already copied it above.)

I'll open an issue about this.

@glasser
Copy link
Member

glasser commented Mar 25, 2021

See #5060 and #5061.

@c4c1us
Copy link
Author

c4c1us commented Mar 26, 2021

Understood ! Thank you for your answer !

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants