graphql-mocks
Version:
Tools for setting up graphql test resolvers
20 lines (18 loc) • 821 B
JavaScript
// These are both illegal characters for GraphQL names and shouldn't appear within any
// type names or field names:
// https://spec.graphql.org/draft/#sec-Names
const FIELD_REFERENCE_HEADER_CHAR = '#';
const FIELD_REFERENCE_SEPARATOR_CHAR = '&';
/**
* Provide a string-only representation of a reference
*/
function maskReference(reference) {
return typeof reference === 'string' ? reference : `${FIELD_REFERENCE_HEADER_CHAR}${reference.join(FIELD_REFERENCE_SEPARATOR_CHAR)}`;
}
function unmaskReference(maskedReference) {
return maskedReference.charAt(0) !== FIELD_REFERENCE_HEADER_CHAR ? maskedReference : maskedReference.slice(1).split(FIELD_REFERENCE_SEPARATOR_CHAR);
}
exports.maskReference = maskReference;
exports.unmaskReference = unmaskReference;
//# sourceMappingURL=reference-mask.js.map
;