Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion docs/design/HC16-upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
This is a high-level companion to PR #3480. The goal here is to give a reader
the *why* behind each non-obvious code change without forcing them to diff Hot
Chocolate v13/v14 against v16 themselves. For the line-level changes, read the
PR.
PR. Sections 1-13 describe the original migration to 16.0.0; section 14 covers
the follow-up to 16.6.4.

---

Expand Down Expand Up @@ -230,3 +231,29 @@ notable test changes are:
`BYTE_TYPE` (`UnsignedByte` → `byte_types`) and `BYTEARRAY_TYPE`
(`Base64String` → `bytearray_types`) because the GraphQL scalar name no
longer matches the test database column-name root.

---

## 14. Follow-up to 16.6.4

The follow-up updates all six centrally managed Hot Chocolate packages from
16.0.0 to 16.6.4. This crosses minor versions, not just patch versions, and
requires two compatibility changes.

Hot Chocolate validates GraphQL input defaults against their field types.
SQL default constraints contain database expressions such as `((1))`,
`(getdate())`, or `('Placeholder')`, not GraphQL literals. Copying those
expressions into create-input defaults can prevent the entire schema from
building.

SQL create fields with database defaults therefore remain nullable but no
longer have a GraphQL input default. Omitting a field lets the database
evaluate its default; supplying an explicit `null` remains distinct and is
still subject to database constraints. This applies to nested and linking
create inputs as well. The source `@defaultValue` metadata is preserved,
and Cosmos GraphQL literal defaults and stored-procedure parameter defaults
are unchanged.

The `FragmentSpreadNode` constructor used in one unit test also needs the
new explicit arguments collection. An empty collection preserves the
argument-free fragment spread used by that test.
12 changes: 6 additions & 6 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.2" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="HotChocolate" Version="16.0.0" />
<PackageVersion Include="HotChocolate.AspNetCore" Version="16.0.0" />
<PackageVersion Include="HotChocolate.AspNetCore.Authorization" Version="16.0.0" />
<PackageVersion Include="HotChocolate.Types.NodaTime" Version="16.0.0" />
<PackageVersion Include="HotChocolate.Utilities.Introspection" Version="16.0.0" />
<PackageVersion Include="HotChocolate.Diagnostics" Version="16.0.0" />
<PackageVersion Include="HotChocolate" Version="16.6.4" />
<PackageVersion Include="HotChocolate.AspNetCore" Version="16.6.4" />
<PackageVersion Include="HotChocolate.AspNetCore.Authorization" Version="16.6.4" />
<PackageVersion Include="HotChocolate.Types.NodaTime" Version="16.6.4" />
<PackageVersion Include="HotChocolate.Utilities.Introspection" Version="16.6.4" />
<PackageVersion Include="HotChocolate.Diagnostics" Version="16.6.4" />
<PackageVersion Include="Humanizer" Version="2.14.1" />
<PackageVersion Include="Humanizer.Core" Version="2.14.1" />
<PackageVersion Include="DotNetEnv" Version="3.0.0" />
Expand Down
23 changes: 16 additions & 7 deletions src/Service.GraphQLBuilder/Mutations/CreateMutationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static class CreateMutationBuilder
// 1. Scalar input fields.
IEnumerable<InputValueDefinitionNode> scalarInputFields = objectTypeDefinitionNode.Fields
.Where(field => IsBuiltInType(field.Type) && !IsAutoGeneratedField(field))
.Select(field => GenerateScalarInputType(name, field, IsMultipleCreateOperationEnabled));
.Select(field => GenerateScalarInputType(name, field, databaseType, IsMultipleCreateOperationEnabled));

// Add scalar input fields to list of input fields for current input type.
// Generate the create input type only if there are any scalar fields that are not auto-generated fields.
Expand Down Expand Up @@ -191,7 +191,7 @@ private static InputObjectTypeDefinitionNode GenerateCreateInputTypeForNonRelati
{
if (IsBuiltInType(field.Type))
{
return GenerateScalarInputType(name, field);
return GenerateScalarInputType(name, field, databaseType);
}

string typeName = RelationshipDirectiveType.Target(field);
Expand Down Expand Up @@ -269,17 +269,26 @@ private static bool DoesFieldHaveReferencingFieldDirective(FieldDefinitionNode f
/// <param name="name">Name of the field.</param>
/// <param name="fieldDefinition">Field definition.</param>
/// <param name="databaseType">Database type</param>
/// <param name="IsMultipleCreateOperationEnabled">Indicates whether multiple create operation is enabled</param>
private static InputValueDefinitionNode GenerateScalarInputType(NameNode name, FieldDefinitionNode fieldDefinition, bool isMultipleCreateOperationEnabled = false)
/// <param name="isMultipleCreateOperationEnabled">Indicates whether multiple create operation is enabled</param>
private static InputValueDefinitionNode GenerateScalarInputType(
NameNode name,
FieldDefinitionNode fieldDefinition,
DatabaseType databaseType,
bool isMultipleCreateOperationEnabled = false)
{
IValueNode? defaultValue = null;
bool isFieldNullable = false;

if (DefaultValueDirectiveType.TryGetDefaultValue(fieldDefinition, out ObjectValueNode? value))
{
defaultValue = value.Fields[0].Value;
}
isFieldNullable = true;

bool isFieldNullable = defaultValue is not null;
// SQL defaults are expressions evaluated by the database, not GraphQL input defaults.
if (!IsRelationalDb(databaseType))
{
defaultValue = value.Fields[0].Value;
}
}

if (isMultipleCreateOperationEnabled &&
DoesFieldHaveReferencingFieldDirective(fieldDefinition))
Expand Down
Loading
Loading