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

Remove init-only properties from pre-.NET 5 targets #3323

Merged
merged 2 commits into from Sep 16, 2022
Merged

Conversation

Shane32
Copy link
Member

@Shane32 Shane32 commented Sep 12, 2022

Fixes #3322

@Shane32 Shane32 self-assigned this Sep 12, 2022
@@ -3022,6 +3022,7 @@ namespace GraphQL.Validation
public readonly struct ValidationOptions
{
public ValidationOptions() { }
public ValidationOptions(GraphQL.Types.ISchema schema, GraphQLParser.AST.GraphQLDocument document, System.Collections.Generic.IEnumerable<GraphQL.Validation.IValidationRule>? rules, System.Collections.Generic.IDictionary<string, object?> userContext, GraphQL.Instrumentation.Metrics metrics, GraphQL.Inputs variables, GraphQL.Inputs extensions, GraphQLParser.AST.GraphQLOperationDefinition operation, System.IServiceProvider? requestServices, System.Security.Claims.ClaimsPrincipal? user, System.Threading.CancellationToken cancellationToken) { }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a read-only struct. To allow C# 8 and prior languages to write to these properties, a constructor was added as a non-breaking change. Changing the struct to a read/write struct is a breaking change and affects other code.

Comment on lines 35 to 39
#if NET5_0_OR_GREATER
init;
#else
set;
#endif
Copy link
Member Author

@Shane32 Shane32 Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minimize impact here. Perhaps just converting to set; would be better, whether it is binary-breaking or not.

See https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/init#breaking-changes

Copy link
Member Author

@Shane32 Shane32 Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this class is not likely to be inherited in 3rd-party libraries, so non-source-breaking is probably acceptable here, even if it is binary-breaking.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to simply set; since we wouldn't want a class library compiled against .NET Standard 2.0 to assume that the property was an init; while the main project is compiled against .NET 6 and assumes the property was a set; therefor having a broken build without any 3rd party references.

@Shane32 Shane32 added this to the 7.1 milestone Sep 13, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #3323 (74efc97) into master (80b966e) will decrease coverage by 0.02%.
The diff coverage is 13.33%.

@@            Coverage Diff             @@
##           master    #3323      +/-   ##
==========================================
- Coverage   84.04%   84.01%   -0.03%     
==========================================
  Files         376      376              
  Lines       16179    16201      +22     
  Branches     2600     2602       +2     
==========================================
+ Hits        13597    13612      +15     
- Misses       1964     1971       +7     
  Partials      618      618              
Impacted Files Coverage Δ
src/GraphQL/Validation/ValidationOptions.cs 50.00% <0.00%> (-50.00%) ⬇️
...hQL/Attributes/Authorization/AuthorizeAttribute.cs 72.54% <100.00%> (ø)
src/GraphQL/Types/GraphQLTypeReference.cs 39.28% <0.00%> (-2.39%) ⬇️
src/GraphQL/Types/Collections/SchemaTypes.cs 88.30% <0.00%> (-0.08%) ⬇️
...aphQL/Types/Composite/ObjectGraphTypeExtensions.cs 41.66% <0.00%> (+41.66%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@Shane32 Shane32 merged commit ca2c139 into master Sep 16, 2022
@Shane32 Shane32 deleted the remove_init branch September 16, 2022 14:46
@sungam3r
Copy link
Member

reviewed

Kent-Chen-Conning added a commit to Conning/graphql-dotnet that referenced this pull request Oct 28, 2022
…TRAC-6694-upgrade-graphql-dotnet-server-to-7.1

* commit '13da37d7c0649cc6186714a6671272af49f06d85': (1255 commits)
  Add type integrity check when existing types are found (graphql-dotnet#3332)
  Switch to Nullability.Source (graphql-dotnet#3314)
  Add missing authorization extensions from field and connection builders (graphql-dotnet#3324)
  Prevent using graphtype as model (graphql-dotnet#3316)
  Remove init-only properties from pre-.NET 5 targets (graphql-dotnet#3323)
  Update UnionGraphType to support CLR references (graphql-dotnet#3320)
  Bump BenchmarkDotNet from 0.13.1 to 0.13.2 (graphql-dotnet#3313)
  Bump Microsoft.NET.Test.Sdk from 17.3.0 to 17.3.1 (graphql-dotnet#3311)
  Fix InputFieldsAndArgumentsOfCorrectLength validation rule (graphql-dotnet#3307)
  Bump Shouldly from 4.0.3 to 4.1.0 (graphql-dotnet#3304)
  Add test (graphql-dotnet#3302)
  !(a is T) -> a is not T (graphql-dotnet#3300)
  User not duplicated in context (graphql-dotnet#3298)
  Bump deps (graphql-dotnet#3295)
  Restore `Field<TGraphType>()` method (graphql-dotnet#3294)
  Include v7 migration document link in readme (graphql-dotnet#3290)
  Bump GraphQL-Parser to 8.1.0 (graphql-dotnet#3289)
  Migration notes updates (graphql-dotnet#3287)
  Simplify configuration (graphql-dotnet#3286)
  Introduce ErrorInfoProviderOptions.ExposeExceptionDetailsMode (graphql-dotnet#3276)
  ...

# Conflicts:
#	docs/package.json
#	src/GraphQL/GraphQL.csproj
#	src/GraphQL/Types/GraphTypesLookup.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot use ValidateAsync in .NET 4.7.1
3 participants