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

Attribute 'Topic' is not valid on this declaration type. It is valid on 'Method' declarations only. #6111

Closed
1 task done
LeXaMeN opened this issue May 3, 2023 · 3 comments · Fixed by #6664
Closed
1 task done
Labels
📚 documentation This issue is about working on our documentation.

Comments

@LeXaMeN
Copy link

LeXaMeN commented May 3, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Product

Hot Chocolate

Describe the bug

Documentation says:

We can even use the Topic attribute on dynamic arguments of the subscription field.
https://chillicream.com/docs/hotchocolate/v13/defining-a-schema/subscriptions#dynamic-topics

Visual Studio says:

Attribute 'Topic' is not valid on this declaration type. It is valid on 'Method' declarations only.

Steps to reproduce

Example:

public class Subscription
{
    [Subscribe]
    public Client ClientUpdated([Topic] int clientId, [EventMessage] Client client) => client;
}

Relevant log output

No response

Additional Context?

No response

Version

13.0.5

@tobias-tengler
Copy link
Collaborator

This was a breaking change as part of v13 as detailed here: https://chillicream.com/docs/hotchocolate/v13/migrating/migrate-from-12-to-13/#topicattribute

The documentation needs to be updated.

@tobias-tengler tobias-tengler added 📚 documentation This issue is about working on our documentation. and removed 🐛 bug labels May 3, 2023
@williamdenton
Copy link
Contributor

when the docs get updated you might want to note that nameof can be used to get the argument name

public class Subscription
{
    [Subscribe]
    // What's inbetween the curly braces must match an argument name.
    [Topic($"{nameof(author)}")]
    public Book BookPublished(string author, [EventMessage] Book book)
        => book;
}

@aokellermann
Copy link
Contributor

when the docs get updated you might want to note that nameof can be used to get the argument name

public class Subscription
{
    [Subscribe]
    // What's inbetween the curly braces must match an argument name.
    [Topic($"{nameof(author)}")]
    public Book BookPublished(string author, [EventMessage] Book book)
        => book;
}

You need extra curly braces here: [Topic($"{{{nameof(author)}}}")]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 documentation This issue is about working on our documentation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants