Skip to content

Conversation

@brendenpalmer
Copy link
Contributor

Simple urn directive example

Comment on lines +62 to +80
if (urnDirectiveArgs) {
const { resolve = defaultFieldResolver } = fieldConfig;

return {
...fieldConfig,
resolve: async function (source, args, context, info) {
const result = await resolve(source, args, context, info);

if (typeof result === 'string') {
const { type, fields = [] } = urnDirectiveArgs;

const baseUrn = `unique_urn_with_parts_${type}`;

if (fields.length) {
return `${baseUrn}:(${fields.map(() => idGenerator())})`;
}

return baseUrn;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for our purposes, but WDYT about having the pattern be regex based so it's more widely applicable than just URNs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants