diff --git a/src/Trax.Effect/Attributes/TraxMutationAttribute.cs b/src/Trax.Effect/Attributes/TraxMutationAttribute.cs index 0c6bb18..22c9fa2 100644 --- a/src/Trax.Effect/Attributes/TraxMutationAttribute.cs +++ b/src/Trax.Effect/Attributes/TraxMutationAttribute.cs @@ -74,6 +74,13 @@ public TraxMutationAttribute(params GraphQLOperation[] operations) /// Clients see a deprecation warning during introspection. /// public string? DeprecationReason { get; init; } + + /// + /// Groups this field under a sub-namespace in the GraphQL schema. + /// When set, the field appears under dispatch { namespace { field } } + /// instead of directly under dispatch { field }. + /// + public string? Namespace { get; init; } } /// diff --git a/src/Trax.Effect/Attributes/TraxQueryAttribute.cs b/src/Trax.Effect/Attributes/TraxQueryAttribute.cs index 1965383..d508629 100644 --- a/src/Trax.Effect/Attributes/TraxQueryAttribute.cs +++ b/src/Trax.Effect/Attributes/TraxQueryAttribute.cs @@ -32,4 +32,11 @@ public class TraxQueryAttribute : Attribute /// Clients see a deprecation warning during introspection. /// public string? DeprecationReason { get; init; } + + /// + /// Groups this field under a sub-namespace in the GraphQL schema. + /// When set, the field appears under discover { namespace { field } } + /// instead of directly under discover { field }. + /// + public string? Namespace { get; init; } } diff --git a/src/Trax.Effect/Attributes/TraxQueryModelAttribute.cs b/src/Trax.Effect/Attributes/TraxQueryModelAttribute.cs new file mode 100644 index 0000000..6ac1579 --- /dev/null +++ b/src/Trax.Effect/Attributes/TraxQueryModelAttribute.cs @@ -0,0 +1,68 @@ +namespace Trax.Effect.Attributes; + +/// +/// Exposes an EF Core entity as a typed GraphQL query field under discover +/// with optional cursor pagination, filtering, sorting, and projection. +/// +/// +/// Place this attribute on entity classes that are exposed via a DbSet<T> +/// on a DbContext registered with AddTraxGraphQL(g => g.AddDbContext<TContext>()). +/// The generated field name is derived by pluralizing and camelCasing the class name +/// (e.g. Playerplayers), or overridden via . +/// +/// Each feature (paging, filtering, sorting, projection) can be individually disabled +/// via the corresponding property. All default to true. +/// +[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] +public class TraxQueryModelAttribute : Attribute +{ + /// + /// Overrides the auto-derived GraphQL field name. + /// When null, the name is derived by pluralizing and camelCasing the class name + /// (e.g. Playerplayers, MatchResultmatchResults). + /// + public string? Name { get; init; } + + /// + /// A human-readable description that appears in the GraphQL schema documentation. + /// + public string? Description { get; init; } + + /// + /// Marks the generated field as deprecated in the GraphQL schema. + /// Clients see a deprecation warning during introspection. + /// + public string? DeprecationReason { get; init; } + + /// + /// Enables cursor-based pagination (Relay Connection spec) on the query field. + /// When true, the field returns a Connection type with nodes, + /// edges, and pageInfo. + /// + public bool Paging { get; init; } = true; + + /// + /// Enables filtering on the query field. When true, clients can use + /// a where argument to filter results by entity properties. + /// + public bool Filtering { get; init; } = true; + + /// + /// Enables sorting on the query field. When true, clients can use + /// an order argument to sort results by entity properties. + /// + public bool Sorting { get; init; } = true; + + /// + /// Enables field projection on the query field. When true, + /// only the columns requested by the client are selected from the database. + /// + public bool Projection { get; init; } = true; + + /// + /// Groups this field under a sub-namespace in the GraphQL schema. + /// When set, the field appears under discover { namespace { field } } + /// instead of directly under discover { field }. + /// + public string? Namespace { get; init; } +}