ChilliCream / ChilliCream/graphql-platform

Multi target directive descriptor attributes

Open
#6,598 3 comments 0 reactions 1 assignee View on GitHub

@michaelstaib is already working on this.

Since Oct 12, 2023.

🌶️ hot chocolate Area: Type System
Dominant language
C#
Stars
5.8k
Forks
810
Avg merge
15h 39m
Merged PRs (30d)
98

Description

Product

Hot Chocolate

Is your feature request related to a problem?

Attributes are convenient way to apply directives in a code-first approach. HotChocolate provides a convenient built-in mechanism that automatically configures type specific DescriptorAttribute.

This works great for directives targeting single location (e.g. FIELD_DEFINITION) but is problematic if we have multiple targets. Built-in HotChocolate directives (TagAttribute, AuthorizeAttribute work around this problem by extending DescriptorAttribute.

Unfortunately this method doesn't work for external projects as DescriptorAttribute currently defines an internal method which means it is not possible to extend it outside of HotChocolate repository.

protected internal abstract void TryConfigure(
        IDescriptorContext context,
        IDescriptor descriptor,
        ICustomAttributeProvider element);

As a result we currently have two workarounds

  • define location specific attribute, e.g. TagFieldAttribute/TagObjectAttribute (which for something like @tag would imply a LOT of different attributes)
  • extend base Attribute, bypass HotChocolate built-in logic and provide custom logic to apply directives in a custom TypeInterceptor
The solution you'd like

The simplest solution would be to allow users extend DescriptorAttribute.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.