Created
August 13, 2020 17:25
-
-
Save Bonitis/07106c388891af98cd7e904ea25d3f44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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