Skip to content

Version 5.0.0-preview004

Pre-release
Pre-release
Compare
Choose a tag to compare
@nikcio nikcio released this 06 May 05:49
· 55 commits to contrib since this release

✨ Highlights

  • Simpler project structure
    • You now only need to reference the Nikcio.UHeadless package to get started as all packages are now merged into one.
  • New defaults for Queries and Models
    • The new defaults are now simpler and limited to the most common useable queries and models.
  • Authorization by default
    • This is still a work in progress but the new defaults will include authorization by default which will help ensure you're not exposing too much data.
  • Easier to use Typed properties
    • This release brings typed or previously 'Named properties' to the forefront and makes them easier to use.
    • Typed properties are now available everywhere it makes sense. (See the feature section for more details)
  • Cleaner setup with new bootstrapping.
    • The new bootstrapping is simpler and more intuitive.

🚀 Features

  • Typed properties are now available everywhere it makes sense.
    • Use the TypedPropertes class for Content items/Media items and Member items
    • Use the TypedNestedContentProperties class for Nested Content items
    • Use the TypedBlockListContentProperties class for Block List items (Content)
    • Use the TypedBlockListSettingsProperties class for Block List items (Settings)
    • Use the TypedBlockGridContentProperties class for Block Grid items (Content)
    • Use the TypedBlockGridSettingsProperties class for Block Grid items (Settings)
  • New defaults for Queries and Models
    • Queries
      • Use ContentAtRootQuery to get content at the root of your Umbraco site.
      • Use ContentByContentTypeQuery to get content by content type.
      • Use ContentByGuidQuery to get content by guid.
      • Use ContentByIdQuery to get content by id.
      • Use ContentByRouteQuery to get content by route.
        • Includes built-in support for the Umbraco automatic redirects.
      • Use ContentByTagQuery to get content by tag.
      • Use MediaAtRootQuery to get media at the root of your Umbraco site.
      • Use MediaByContentTypeQuery to get media by content type.
      • Use MediaByGuidQuery to get media by guid.
      • Use MediaByIdQuery to get media by id.
      • Use FindMembersByDisplayNameQuery to get members by thier display name.
      • Use FindMembersByEmailQuery to get members by email.
      • Use FindMembersByRoleQuery to get members by role.
      • Use FindMembersByUsernameQuery to get members by username.
      • Use MemberByEmailQuery to get a member by email.
      • Use MemberByGuidQuery to get a member by guid.
      • Use MemberByIdQuery to get a member by id.
      • Use MemberByUsernameQuery to get a member by username.
    • Models
      • ContentItem is used for Content queries. This has built-in support for redirect information provided by ContentByRouteQuery.
      • MediaItem is used for Media queries.
      • MemberItem is used for Member queries.
      • BlockGrid to support the block grid editor.
      • BlockList to support the block list editor.
      • ContentPicker to support the content picker editor and the multi node picker.
      • DateTimePicker to support the date time picker editor.
      • DefaultProperty to support editors that doesn't require special modeling. (Used as the fallback)
      • Label to support the label editor.
      • MediaPicker to support the media picker editor.
      • MemberPicker to support the member picker editor. (Now requires Authorization by default to avoid leaking member information. This can be disabled by setting options.DisableAuthorization)
      • MultiUrlPicker to support the multi url picker editor.
      • NestedContent to support the nested content editor.
      • RichText to support the rich text editor and the markdown editor.
      • UnsupportedProperty to mark properties that are not supported.
  • Authorization by default [Work in progress]
    • Authorization is now enabled by default for all queries to have secure by default queries.
    • Authorization is now enabled by default for the MemberPicker model to avoid leaking member information.
    • This can be disabled by setting options.DisableAuthorization in the UmbracoHeadlessOptions.
  • New bootstrapping
    • Bootstrapping is now simpler and more intuitive. (See the getting started guide at the bottom of this release note)
  • The new ContentPicker model now supports querying the properties of the picked content.
  • The IResolverContext from HotChocolate has now been added to the default commands so it can be used to resolve services and access query arguments like Culture, IncludePreivew, Fallback and Segment.
  • ContentByContentTypeQuery now supports includePreview to fetch preview content. #229
  • Context data like Culture, IncludePreivew, Fallback and Segment are now provided with the inContext parameter object on content queries.
  • Instead of the UsePaging attribute from HotChocolate a new Paginationresult model has been added to avoid problems with the way Umbraco handles content data on queries. This means that the UsePaging attribute is no longer needed and shouldn't be used in custom queries either.

🧪 Test improvements

  • Content query tests have been rewritten and are now more stable.
  • Media query tests have been rewritten and are now more stable.

🏛️Project stability

  • All projects are now merged into one which makes maintenance easier as this also removes a lot of code as the package could be simplified.
  • A new Nikcio.UHeadless.LegacyModels project has been added to help with migration from the old schema to the new schema. (This won't be available as a package but will be available for use for people migrating).

📦 Dependencies

  • HotChocolate.Data has been removed as it's no longer needed.

💥 Breaking changes.

  • This release is a complete overhaul of the project and therefore a lot of things have changed. A migration guide will be written to help with the migration.

🚧 Try out the preview - Getting started

To get up and running with this preview you can follow the steps below.

  1. Install the Nikcio.UHeadless package.
  2. Add the following code to your program.cs file.
using Nikcio.UHeadless;
using Nikcio.UHeadless.Defaults.ContentItems;
using Nikcio.UHeadless.Defaults.MediaItems;
using Nikcio.UHeadless.Defaults.Members;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

builder.CreateUmbracoBuilder()
    // ... Default Umbraco setup
    .AddUHeadless(options =>
    {
        // Disable authorization for now as this is still work in progress.
        options.DisableAuthorization = true; 

        options.AddDefaults();

        options
            .AddQuery<ContentByRouteQuery>()
            .AddQuery<ContentByContentTypeQuery>()
            .AddQuery<ContentAtRootQuery>()
            .AddQuery<ContentByIdQuery>()
            .AddQuery<ContentByGuidQuery>()
            .AddQuery<ContentByTagQuery>();

        options
            .AddQuery<MediaByContentTypeQuery>()
            .AddQuery<MediaAtRootQuery>()
            .AddQuery<MediaByIdQuery>()
            .AddQuery<MediaByGuidQuery>();

        options
            .AddQuery<FindMembersByDisplayNameQuery>()
            .AddQuery<FindMembersByEmailQuery>()
            .AddQuery<FindMembersByRoleQuery>()
            .AddQuery<FindMembersByUsernameQuery>()
            .AddQuery<MemberByEmailQuery>()
            .AddQuery<MemberByGuidQuery>()
            .AddQuery<MemberByIdQuery>()
            .AddQuery<MemberByUsernameQuery>();
    })
    .Build();

WebApplication app = builder.Build();

await app.BootUmbracoAsync().ConfigureAwait(false);

app.UseAuthentication();
app.UseAuthorization();

app.MapGraphQL();

app.UseUmbraco()
    // ... Default Umbraco setup

await app.RunAsync().ConfigureAwait(false);
  1. Run your application and navigate to /graphql to see the GraphQL playground.
  2. Fire off a query.
query {
  contentAtRoot{
    items {
      url(urlMode: ABSOLUTE)
      name
      id
      properties {
        __typename
      }
    }
  }
}
  1. Query your properties. To figure out what fragment to write you can use the __typename from the previous response. Just make sure to add an I. You can also use composition types to create fragments.
query {
  contentAtRoot{
    items {
      url(urlMode: ABSOLUTE)
      name
      id
      properties {
        ... on IMyContentType {
          
        }
        __typename
      }
    }
  }
}