UNPKG

graphql-compose-relay

Version:

Plugin for `graphql-compose` which wraps graphql types with Relay specific logic.

27 lines (25 loc) 752 B
export function base64(i) { return Buffer.from(i, 'ascii').toString('base64'); } export function unbase64(i) { return Buffer.from(i, 'base64').toString('ascii'); } /** * Takes a type name and an ID specific to that type name, and returns a * "global ID" that is unique among all types. */ export function toGlobalId(type, id) { return base64([type, id].join(':')); } /** * Takes the "global ID" created by toGlobalID, and returns the type name and ID * used to create it. */ export function fromGlobalId(globalId) { const unbasedGlobalId = unbase64(globalId); const delimiterPos = unbasedGlobalId.indexOf(':'); return { type: unbasedGlobalId.substring(0, delimiterPos), id: unbasedGlobalId.substring(delimiterPos + 1) }; }