Skip to content

Instantly share code, notes, and snippets.

@Bonitis
Created August 13, 2020 17:25
Show Gist options
  • Save Bonitis/07106c388891af98cd7e904ea25d3f44 to your computer and use it in GitHub Desktop.
Save Bonitis/07106c388891af98cd7e904ea25d3f44 to your computer and use it in GitHub Desktop.
{
transformRequest: (request: Request): Request => {
const {document, variables} = request;
const newDocument = visit(document, {
Field: (node: FieldNode): FieldNode | undefined => {
if (
operation === 'mutation' &&
node.name.value === 'result' &&
remoteReturnType &&
'getFields' in remoteReturnType
) {
const fields = remoteReturnType.getFields();
const replacementField = find(fields, f => f.type.toString() === returnType);
return replacementField?.name ? renameFieldNode(node, replacementField.name) : node;
}
return node;
}
});
return {document: newDocument, variables};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment