Closed AlecAivazis closed 1 year ago
Hey @olmo-hake!
Sorry to hear you're running into this! Would you be able to push up a reproduction somewhere I can take a look? I tried to reproduce it in our test suite but the variables were being correctly removed from the mutation 🤔
Hi @AlecAivazis,
thanks for the quick response! I quite busy at the moment and tbh not sure how to quickly reproduce the problem. Can you test with out a corresponding graphql endpoint based on the sveltekit project alone? Will work around it for now via manuall array updates and come back to it as soon as i have a bit more time and a better idea how to reproduce it.
Okay no problem. I'll go ahead and close this issue. Feel free to open another one when you have some time to dig into what could be happening 👍
@AlecAivazis I think you were refering to this: https://github.com/HoudiniGraphql/houdini/blob/3b43098c20dd6fa95c8fb1b8f52568832e2033ee/packages/houdini/src/codegen/generators/artifacts/tests/artifacts.test.ts#L319
But it seems that the parentID is still in the Input section. What OP is trying to say is that the variables are forwarded to the grqphql backend which then complains that it is handed variables which are not actually being used inside the query...
UPDATE:
I did execute the tests and the variables are successfully removed. Seems the document forwarded to the server is different, or there is a different reason like additional parameters in the query which prevent correct removal etc.
Huh so your seeing a situation where the artifact's raw
value isn't what is sent to the API?
Not exactly. But I see that the variable I use in the Mutation are being sent to the server. The directive @parentID has been removed. With the variable still present the server rejects the Mutation stating there are "unexpected variables"...
Ok, so I put my schema and my docs into your test suite and ran 'variables only used by internal directives are scrubbed'. The result is that the variables are successfully removed from my the resulting raw. They are still in the resulting "input". I guess the error must be somewhere else. Maybe not sending the sanitized doc over to the server?!
I worte a Plugin to resolve this in the meantime...
const SanitaizeVariablesOnlyUsedByDirectivesPlugin: ClientPlugin = () => {
return {
// remove all variables from ctx.stuff.inputs.marshaled objects which are not in the ctx.text
// this is needed because the HoudiniClient will send all variables to the server
// even if they are not used in the query
beforeNetwork(ctx, { next }) {
if (ctx.stuff?.inputs?.marshaled) {
ctx.stuff.inputs.marshaled = Object.keys(ctx.stuff.inputs.marshaled).reduce((acc, key) => {
if (ctx.text.includes(key)) {
acc[key] = ctx.stuff.inputs.marshaled[key];
}
return acc;
}, {});
}
// move onto the next step in the pipeline
next(ctx);
},
// restore the ctx.stuff.inputs.marshaled objects from ctx.variables
afterNetwork(ctx, { resolve }) {
if (ctx.stuff?.inputs?.marshaled && ctx.variables) {
ctx.stuff.inputs.marshaled = structuredClone(ctx.variables);
}
// move onto the next step in the pipeline
resolve(ctx);
}
};
};
@AlecAivazis Is this about right? Any side effects to consider?
@AlecAivazis . I am also facing this issue.
userId
should not be send to our GQL backend.
can you please help with this.
const deletePersonalAccessToken = graphql(`
mutation DeletePersonalAccessToken($id: uuid!, $userId: ID!) {
deleteAuthRefreshToken(id: $id) {
...Personal_Access_Tokens_remove @parentID(value: $userId)
}
}
`);
Discussed in https://github.com/HoudiniGraphql/houdini/discussions/1006