Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple urn directive example #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Simple urn directive example #6

wants to merge 1 commit into from

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.

2 participants