Comments (2)
After further thought the extra values in the [GraphFIeld]
are not necessary. As of today, since all INPUT_OBJECT types are first created from a parameterless constructor there exists an opportunity for developer code to set any necessary values. We only then need the ability to mark fields as non-nullable when they otherwise would be due to type constraints. This is mostly around value types such as int
, double
etc.
While it is possible today to mark a field as required or not using the [GraphField]
attribute its a bit limiting and not very intuitive.
[GraphField(TypeExpressions= TypeExpressions.None)]
- Will Mark an otherwise required property (such as an int) as being not required
[GraphField(TypeExpressions= TypeExpressions.IsNotNullable)]
- Will mark a nullable property (such as a reference) as being required.
Since declaring a type expression overrides what the templating engine would glean about the property return type, you run into trouble if the property is a list. You would have to redeclare the entire list structure as part of the TypeExpression field in order to maintain its correctness if you wished to apply "non-nullability" to the list.
This is exceedingly cumbersome and verbose.
Proposal (Breaking Change):
It is in error to force an value type property to be required in a query unless otherwise stated by the user.
Take a page from ASP.NET and the use of [Required]
(from System.ComponentModel) for deserializing objects during rest queries. If a field is attributed with [Required]
then it must be supplied. Otherwise its value will be set to whatever is the value of default(Type)
is or a value supplied during the object's constructor.
This would be a breaking change in that it changes the default behavior for value type fields on INPUT_OBJECT types. However, in the spirit of conforming to ASP.NET standards and general expectations of ASP.NET developers, this change should prove better in the long run.
// assume this class is registered as an INPUT_OBJECT
public class Person
{
Person()
{
this.IsHappy = true; // set a default value during object creation
this.Child = null;
}
// NOT required in a query
// Expresssion: 'String'
// Default Value: <null> | as defined by default(string)
public string FirstName { get; set; }
// REQUIRED in a query
// Expresssion: 'String!'
// Default Value: -Not defined-
[Required]
public string LastName { get; set; }
// REQUIRED in a query
// Expresssion: 'Address!'
// Default Value: -Not defined-
[Required]
public Address Address { get; set; }
// NOT REQUIRED in a query
// Expresssion: 'Person'
// Default Value: null | as set in the constructor
public Person Child { get; set; }
// NOT REQUIRED in a query
// Expresssion: 'Bool'
// Default Value: true | as set in the constructor
public bool IsHappy { get; set; }
// NOT REQUIRED in a query
// Expresssion: 'Int'
// Default Value: 0 | as set by default(int)
public int Age{ get; set; }
// REQUIRED in a query
// Expresssion: 'Int!'
// Default Value: - Not Defined -
[Required]
public int BirthOrder { get; set; }
}
from graphql-aspnet.
released as part of v0.12.0-beta
from graphql-aspnet.
Related Issues (20)
- Method-based field inheritance is not working
- How to use the new MuitipartRequestServerExtension() with a Custom-HttpProcessor ? HOT 2
- Order of assigning Custom Http Processors with the Multipart Extension
- Unable to use TestServerBuilder for Unit Testing HOT 4
- Change controller type name HOT 2
- Controller inheritance not working with Multi-Schema HOT 1
- Marking object fields as non-null HOT 1
- GraphQL filter case insensitive HOT 3
- Remove Moq Dependency
- Unable to use with a scoped IAuthorizationHandler HOT 1
- All object types must define at least one field. HOT 1
- Race condition when building test server
- Error when building same schema for different service collections
- [Q]: How to add pagination easilly HOT 6
- Support for models (classes) with danish letters (æ, ø, å) and in capitalized form ('Æ', 'Ø', 'Å') HOT 2
- I get a GraphTypeDeclarationException when using IGraphActionResult HOT 1
- How to allow anonymous requests for introspection schema? HOT 3
- Infer nullable from C# nullable reference types
- Exposing requested fields for eager loading HOT 3
- How to perform service registration in a .NET 8 project with a Startup file? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-aspnet.