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

Prevent using graphtype as model #3316

Merged
merged 5 commits into from Sep 16, 2022
Merged

Prevent using graphtype as model #3316

merged 5 commits into from Sep 16, 2022

Conversation

Shane32
Copy link
Member

@Shane32 Shane32 commented Sep 6, 2022

Implemented within ComplexGraphType<TSourceType>

Applies to:

  • ObjectGraphType<TSourceType>
  • InputObjectGraphType<TSourceType>
  • AutoRegisteringObjectGraphType<TSourceType>
  • AutoRegisteringInputObjectGraphType<TSourceType>

@Shane32 Shane32 self-assigned this Sep 6, 2022
@github-actions github-actions bot added the test Pull request that adds new or changes existing tests label Sep 6, 2022
@Shane32
Copy link
Member Author

Shane32 commented Sep 6, 2022

This PR doesn't work because __Type derives from ObjectGraphType<IGraphType>. Options:

  1. Change __Type to derive from ObjectGraphType rather than ObjectGraphType<IGraphType>. This would technically be a breaking change
  2. Ignore the check for built-in types like __Type
  3. Move the checks into the auto-registering graph type constructors (Prevent using graphtype as model - alt #3317)

@Shane32
Copy link
Member Author

Shane32 commented Sep 6, 2022

Solution 2 implemented here

@codecov-commenter
Copy link

Codecov Report

Merging #3316 (3d73430) into master (80b966e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #3316   +/-   ##
=======================================
  Coverage   84.04%   84.04%           
=======================================
  Files         376      376           
  Lines       16179    16181    +2     
  Branches     2600     2601    +1     
=======================================
+ Hits        13597    13599    +2     
  Misses       1964     1964           
  Partials      618      618           
Impacted Files Coverage Δ
src/GraphQL/Types/Composite/ComplexGraphType.cs 51.72% <100.00%> (+0.37%) ⬆️

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 c458360 into master Sep 16, 2022
@Shane32 Shane32 deleted the no_graphtype_as_model branch September 16, 2022 14:46
@Shane32 Shane32 added this to the 7.1 milestone Sep 16, 2022

Query = query;
}
}

public class DataGraphType : ObjectGraphType<DataGraphType>
Copy link
Member

Choose a reason for hiding this comment

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

Ha)

Copy link
Member

Choose a reason for hiding this comment

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

That means that in theory in very specific cases someone may want to inherit from ObjectGraphType<OtherGraphType>.

@@ -17,6 +17,9 @@ public abstract class ComplexGraphType<TSourceType> : GraphType, IComplexGraphTy
/// <inheritdoc/>
protected ComplexGraphType()
{
if (typeof(IGraphType).IsAssignableFrom(typeof(TSourceType)) && GetType() != typeof(Introspection.__Type))
Copy link
Member

Choose a reason for hiding this comment

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

🤔 Maybe in future we introduce some flag (GlobalSwitch?) to allow this behavior.

Copy link
Member

Choose a reason for hiding this comment

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

I understand that for 99,99% cases this check helps to solve developer problems.


Query = query;
}
}

public class NullableSchemaType : ObjectGraphType<NullableSchemaType>
Copy link
Member

Choose a reason for hiding this comment

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

Ah, even one more place.

Copy link
Member Author

Choose a reason for hiding this comment

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

These are tests, after all - would they really be coded like this for production use? I highly doubt it — running all the graph constructor code for a data model? Seems highly unlikely.

Could be though - I’m not sure.

Copy link
Member

Choose a reason for hiding this comment

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

Tests, yes. We ourselves write a code that should not be written.

@Shane32
Copy link
Member Author

Shane32 commented Sep 19, 2022

Maybe a global switch. I figured that (a) if there’s a problem then someone will raise an issue (b) people can use the non-generic version of ObjectGraphType if necessary in these rare circumstances.

I suggest we wait until someone complains before adding a global switch.

sungam3r added a commit that referenced this pull request Sep 19, 2022
sungam3r added a commit that referenced this pull request Sep 19, 2022
@sungam3r
Copy link
Member

Of course.

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
test Pull request that adds new or changes existing tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants